title: how can signals interrupt a system call
body: <p>I was reading an article and I read the following: <strong>Suppose we want to execute an external command and wait until it exits. We don't want to wait forever, we want to set some timeout after which we will kill the child process. How to do this? To run a command we use fork(2) and execve(2). To wait for a specific process to exit we can use the waitpid(2) function, but it has no timeout parameter. We can also create a loop in which we call sleep(3) with the timeout as an argument and use the fact that sleep(3) will be interrupted by the SIGCHLD signal. This solution will work... almost. It would contain a race condition: if the process exits immediately, before we call sleep(3) we will wait until the timeout expires. It's a race similar to the one described previously.</strong> How is the system call interrupted? does the child send the signal to the parent process or the the system call sleep(3)? I don't get how the system call stop execution and passes to the parent process, is the system call like another process?</p>