-1

I have created a named pipe (mkfifo) in process 1 and written something on it. Now I can read the content written by process 1 in process 2.

Now I can to something (like listen) by which process 2 comes to know that process 1 has written some thing.

Vivek Kumar
  • 4,822
  • 8
  • 51
  • 85

2 Answers2

0

To complete the comment of Joachim.

You should consider using select or poll

What are the differences between poll and select?

Community
  • 1
  • 1
nlko
  • 500
  • 1
  • 6
  • 9
  • I'v tried to look into select(), poll() & epoll() api. Although I didn't have linux machine to try now, But it seems that it is good for monitoring IO operation. mkfifo is also file, but in my particular case I know when I'm writing to pipe in process 1 & I just want to infor process 2 about this. What do you think about sending custom signal across theses processes. Is it possible, to send custom signal? What will the pros & cons if possible? Thanks a lot for your reply! – Vivek Kumar Feb 07 '14 at 04:48
  • Normally if process 2 has is waiting (using poll or select) on this fifo, it will wake up when there are something in the pipe to receive or if it was closed by process 1. You don't need a signal for that. But if you really need you should be able to use a signal (If you are not sure which one to use or not, use user signals : SIGUSR1 and SIGUSR2.) – nlko Feb 07 '14 at 09:30
  • process 2 will be doing other-things, but at the moment process 1 write something then in that case I want the process 1 to handle that request. Process 2 does not be in BLOCKING state waiting. – Vivek Kumar Feb 07 '14 at 11:23
  • But now if I use signal for this purpose, then I will not be able to able to manage process 2 correctly. As a the moment process 2 will receive the signal from process 1, it will stop the current execution and start doing task mentioned in the signal handler function, and at this stage process 2 might be in some undesired state. Here I need to do something for the same. Any Suggestion please??? – Vivek Kumar Feb 07 '14 at 11:27
  • I can't help too much on that it is architecture/design trouble and higly depends on the purpose of your software. My opinion is you should make a process 3, taking care of receiving the data and sharing a reception buffer with process 2 (beware of mutual exclusion troubles). (process 2 and process 3 are like 2 thread in the same software) – nlko Feb 07 '14 at 11:43
  • @niko thanks a lot for your time. Now I don't have much patience and knowledge to handle the third process. – Vivek Kumar Feb 07 '14 at 12:03
0

I don't know if I really got your question but, if you want to process 2 know when process 1 write something, I suggest you use a signal from the process 1 to warn process 2 that things are ready to be read.(there are another ways to do this as well)
Since you got both process IDs(pid) you can use kill to send your ready message, so from the process that has done writting, it will be like that:
kill(pid, SIGINT)
And then handle Interrupt signal as you wish:

struct sigaction sigtohandle;
memset (&sigtohandle, 0, sizeof (sigtohandle));
sigtohandle.sa_handler = &read_process;
sigaction (SIGINT, &sigtohandle, NULL);

So you will have a function called read_process() on the signal receiver process that is supposed do the job you desire.

You can read more about processes and signals here:

http://advancedlinuxprogramming.com/alp-folder/alp-ch03-processes.pdf

rfermi
  • 179
  • 11
  • This is a terrible idea and entirely unnecessary. – Duck Feb 06 '14 at 17:25
  • In my particular case, I know when I'm writing to pipe in process 1 & I just want to inform process 2 about this. What do you think about sending custom signal across. Is it possible? – Vivek Kumar Feb 07 '14 at 04:51