Thursday, July 30, 2015

python: reading fifo example


fifo - first-in first-out special file, named pipe

A FIFO special file (a named pipe) is similar to a pipe, except that
       it is accessed as part of the filesystem.  It can be opened by
       multiple processes for reading or writing.  When processes are
       exchanging data via the FIFO, the kernel passes all data internally
       without writing it to the filesystem.  Thus, the FIFO special file
       has no contents on the filesystem; the filesystem entry merely serves
       as a reference point so that processes can access the pipe using a
       name in the filesystem.

SEE ALSO  




fifo reader code:

#!/usr/bin/python


__author__ = "Ali Okan Yuksel <okan@siyahsapka.org>"

import sys



def main():
        print "INFO application started"
        fifo="okantest.fifo"
        fd=open(fifo,"r")
        while True:
                line = fd.readline()
                if line !="":
                        sys.stdout.write(line)


if __name__=="__main__":
        main()


data sender bash call:

[root@logserver ~]# for i in `seq 1 1000`; do echo $i > /opt/proxy/okantest.fifo ; done

No comments:

Post a Comment