Problem with Asynchronous Notification

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 

Hi,

 

I am having one doubt, need your help.

 

Can anyone tell me how can we use the poll() or select() system call with asynchronous mechanism.

Let’s take the following example:

 

Let’s say our process is using the asynchronous mechanism by having the following code:

 

signal(SIGIO, &input_handler);

fcntl(STDIN_FILENO, F_SETOWN, getpid());

oflags = fcntl(STDIN_FILENO, F_GETFL);

fcntl(STDIN_FILENO, F_SETFL, oflags | FASYNC);

 

In above code, as we can see, we are registering the signal handler for SIGIO with kernel.

In second line it is setting the file owner to the process owner. In fourth line we are setting the asynchronous flag on.

 

After this the STDIN (Standard input file, fd = 0) will deliver the SIGIO signal to our process, whenever some input comes on input file (when we type something on keyboard). At this instance of time, control comes to our signal handler, which has been defined in our program and we can take action according to SIGIO signal.

 

Now my question is: If we do the same thing for more than one open file, I mean if we enable the asynchronous flag, as shown above, for more than one open file (let’s say, standard input file, standard output file and any other regular file as well), how the signal handler will come to know which file has actually initiated or delivered the SIGIO signal.

 

As far as I can think and have also read in Rubini’s book, we can make use of poll() or select() system calls in signal handler to know which file or set of files has asynchronously delivered the SIGIO signal, but the problem is if we have two or more than two files (which has been set for asynchronous notification) which delivers SIGIO at same time, even poll and select can not help, because poll() and select () system call returns integer which specifies the number of files which are ready for a particular event (read or write or anything else we queried for). poll() and select() system calls do not tell, which particular file or file descriptor has an event to perform.

 

I hope I have not confused you on this. Well if anyone of you knows a solution to it, please reply back.

 

Regards,

Gaurav


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux