Hello,
I would like to ask you for a little help with program I'm working on. I have problems with signals and synchronizing processes (I'm quite new to this part of programming).
Process "parent" creates new child process "child1" and this process creates new child process "child2". The "child2" process sends a SIGUSR2 signal to "child1" process to inform that he is ready to do something. When "child1" receives SIGUSR2 from "child2", he sends a SIGUSR2 signal to "parent" process to inform that he is ready too. When "parent" receives SIGUSR2 from "child1", he sends SIGUSR1 to "child1". Now "child1" do something. When finished, "child1" sends SIGUSR2 to "child2". Now "child2" do something. When finished, sends SIGUSR2 to "child1" and ends. When "child1" receives SIGUSR2, he sends SIGUSR2 to "parent" and ends. When "parent" receives SIGUSR2, he does something and ends.
Hope you understand :)
Below is my code. If you are familiar with signals, can you please cut&paste the code and spend several minutes of your time to try to find what is wrong?
Expected output should be:
* Child2: sending SIGUSR2 to child1
* Child1: child2 is ready
* Parent: child1 is ready
Child1: received signal from parent, do something
Child2: received signal from child1, do something
*** child2 end ***
*** child1 end ***
Parent: received signal from child1, do something
*** parent end ***
But I only get:
* Child2: sending SIGUSR2 to child1
* Child1: child2 is ready
* Parent: child1 is ready
Child1: received signal from parent, do something
And sometimes even without the last sentence.
Thanks you very much for any help.
Last edited by Perderabo; 05-02-2006 at 06:53 PM..
Reason: Disable smilies and add code tags for readability.
You have at least one race condition. Try installing the signal handlers before you fork. When I tried it, child two sent the signal before the parent installed the handler, so the parent ignored the signal (and then installed the handler and waited for the signal it just discarded.)
It works!!!
Thanks for your advice. But it wasn't the only one problem there. There was also problem with the signal masks. I thought that every process has to create new mask to block signals, but it's enough to do this in the parent process.
(well, I'm not sure if this explanation is correct, but it works and I'm happy )
Hello and thanks in advance for any help anyone can offer me
I've been reading up on process signal calls (sighup, sigint, sigkill & sigterm) and I understand they all have different methods of terminating a running process. From what I've also read is a exit() actually terminates a process. ... (2 Replies)
Hello
I would like to create an application with communication between processes,
application tightly coupled, have you please an idea about an API or
a tool that allows me to generate such application?
Thank you so much (11 Replies)
Hi All,
In my program i am handling SIGHUP signal. In the handler i fork and then exec on child process same binary file which is running. Parent process will die after 10 mins.
Now my child process which was exec with same binary file is not receiving SIGHUP signal. Below is the progran code:... (6 Replies)
Too generic to post elsewhere, too advanced for the newbie forums. There are some applications within the unix/linux milieu that understand signals such as SIGHUP, etc as instructions to perform administrative tasks (clearing information out of this, disconnect users, etc.) I was just wondering if... (2 Replies)
i want to write a C chat program that communicates over IPC(inter process communication), that could be run using 2 seperate terminal windows within the same computer. so that wat u type in one terminal window , should appear on the other and vice versa...
could some one please help me with the... (2 Replies)
hello,
I am gettin problem while sending and recieving data through seial port...
when I am sending Data then the reciever end is not able to recieve that data .....
Reciever end is running in infinite loop just polling after some time to check that there is data on the port and then again... (9 Replies)
Hi,
I am thinking about writing a log daemon for a multi-processed ksh application (yes - I know that high-level language would be a better option).
My question is as follows:
If many processes (many scripts) will try writing to a single log file:
print "message" > common.log
Will it work or... (2 Replies)
signal in process communication:
I 'm a example in sun_unix that signal in process communication
It's here down but I only have freebsd in my machine.
how can i do the same in freebsd
eg:
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
int
main( void ){
void... (2 Replies)
We have two Sun Sparc systems running on the xxx.xxx.1.xxx network and can be access fine by machines on that subnet. We are able the ping one of the machines from the xxx.xxx.2.xxx network, but we are not able to ping or communicate with the other machine on the (1) subnet from the (2) subnet.
... (8 Replies)
unix IPC
i would like to know the method of usage of semaphores on shared memory segments the topic seems very difficult to understand mainly when difrent proceses communicate instantly and how do i avaoid deadlock situation (2 Replies)