A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

  • Index
  • » Processes
  • » Curious behavour with accept() and user signal

#1 2003-03-14 11:54 AM

Registered: 2003-03-14
Posts: 2

Re: Curious behavour with accept() and user signal

I have created a daemon, which fork()s off about 8 further processes, each either a single socket server or a client.
I'm using simple blocking in a while true loop since the servers have only socket to look at.

The first process (the original daemon) after spinning off the other processes, is then used make sure the other processes are still running, and in the event of a process failing for some reason, creating a new one.

Now, in order to check the processes are running, i was sending the signal SIGUSR1 using the kill() command and looking at the returned value every 10 seconds. The signal handler in the child process did nothing.

i was finding that the servers accept() function was failing when the signal was sent with the error: 'interrupted system call', However, when i sent the signal 0 this was not occuring (no handler has been written for this).

This isn't really a problem as i can continue to use 0 signal, but i'm wondering what was going on. Also, is sending a signal a reasonable way of checking a process is still running?



#2 2003-03-14 02:32 PM

From: Boston, MA
Registered: 2002-06-12
Posts: 3,847

Re: Curious behavour with accept() and user signal

Sending signal 0 is designed for just that purpose: checking whether a
process is alive or not...  It doesn't actually send a REAL signal, at all...
It's just a simple live-or-dead test...  So, that's why sending it doesn't
interrupt your system calls...  But, sending a REAL signal, such as
SIGUSR1 will certainly interrupt your syscalls...  And, unless your
system auto-restarts interrupted syscalls, they will fail with EINTR, as
you're seeing...  So, yes, this is expected behavior...  And, really, you
should be handling it in your code, by wrapping your blocking syscalls
like accept() in a loop like so:

do {
    newfd = accept (listenfd, &client, &clientlen);
} while ((newfd < 0) && (errno == EINTR));

But, if you just want to check if the process is alive or dead, definitely
stick with sending 'signal' 0, rather than SIGUSR1, anyway...


  • Index
  • » Processes
  • » Curious behavour with accept() and user signal

Board footer

Powered by FluxBB