Sunday, October 14, 2012

File Descriptors in GNU Radio

When a program opens a file, the operating system returns a corresponding file descriptor that the program refers to in order to process the file. A file descriptor is a low positive integer.

The first three file descriptors (0,1, and 2,) are associated with the standard input (stdin), the standard output (stdout), and the standard error (stderr), respectively.

Lets take following example in GNU Radio :

# open socket output :
         self.fd = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 

# socket() is also an operator which returns the file descriptor number

# fd will contain the value 1 as it is related to output at port 7001
# this value of fd is used as input argument to the gr_file_descriptor_source/sink
         self.file = gr.file_descriptor_sink(gr.sizeof_gr_complex,self.fd.fileno() )

file descriptor can also be obtained in python by

seld.fid = open(....)

example :

self.file = open(filename,"w") = gr.file_descriptor_sink(gr.sizeof_short,self.file.fileno()) 

To use a gr_file_descriptor, you need to open the file  yourself beforehand, the closing should thus happen in the same scope.

Reference :

Here is the wikipedia link about file descriptors, here you can see the general operators which create a file descriptors as well the common operation which can be done on file descriptors  

details of gr_file_descriptor are at :


No comments:

Post a Comment