Andres Perez
Andres Perez

Reputation: 159

When a process call the sleep function, does it emit a signal?

I'm forking a process in my program, and this process calls a exec() function, then the child process calls the sleep() function.

I want to know if the sleep() function sends some kind of signal that the parent can detect, and if so, what type of signal does it send?

Upvotes: 3

Views: 2226

Answers (2)

paxdiablo
paxdiablo

Reputation: 881633

No, sleep itself doesn't send any sort of signal to the parent, it may use signals under the covers to wake itself up, but that's totally internal to the child.

If you want to notify the parent, you'll have to do that yourself before sleeping. That may be as simple as:

#include <sys/types.h>
#include <unistd.h>
#include <sys/signal.h>
:
kill (getppid(), SIGHUP);

Upvotes: 3

mvp
mvp

Reputation: 116207

Typically sleep() is implemented by calling alarm(2) which arranges for a SIGALRM signal to be delivered to the calling process once timeout expires.

In other words, signal is sent after sleep is finished sleeping, just not to the parent process - but to process which called sleep. And parent process cannot intercept signals delivered to its child.

Upvotes: 4

Related Questions