Tim
Tim

Reputation: 99428

Does sleep() wake up a process by sending some signal at the end of waiting?

APUE says about sleep()

This function sleep() causes the calling process to be suspended until either

  1. The amount of wall clock time specified by seconds has elapsed.
  2. A signal is caught by the process and the signal handler returns.

Does the first case work by sending some specific signal to the process itself? If yes, what is the signal? alarm() can send signal SIGALARM to the calling process after a specific time period, which is why I wonder if sleep() work in the same way.

Does sleep() change the state of the calling process to the same state as sigsuspend() changes to? Which process state(s) do the two functions change to?

Is it correct that a suspended process can only be waken by a signal? That is the reason why I have the question.

Thanks.

Upvotes: 1

Views: 1393

Answers (1)

Tsyvarev
Tsyvarev

Reputation: 65938

Linux kernel has absolutely no needs in using user signals for change the state of the process. So, a signal emitting is performed only for meet a requirement on a user library's function.

As documentation for sleep function doesn't say that any signal is emitted after the end of the sleep, so the kernel doesn't use signals in that case.

Is it correct that a suspended process can only be waken by a signal?

Yes, user code may awoke sleeping process only by sending signal to it. This is true for most non-runnable process states too.

Upvotes: 2

Related Questions