Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does a process handle a signal

Tags:

linux

signals

I want to know when does a linux process handles the signal. Assuming that the process has installed the signal handler for a signal, I wanted to know when would the process's normal execution flow be interrupted and signal handler called.

According to http://www.tldp.org/LDP/tlk/ipc/ipc.html, the process would handle the signal when it exits from a system call. This would mean that a normal instruction like a = b+c (or its equivalent machine code) would not be interrupted because of signal.

Also, there are system calls which would get interrupted (and fail with EINTR or get restarted) upon receiving a signal. This means that signal is processed even before the system call completes. This behaviour seems to b conflicting with what I have mentioned in the previous paragraph.

So, I am not clear as to when is the signal processed and in which process states would it be handled by the process. Can it be interrupted

  1. Anytime it enters from kernel space to user space, or
  2. Anytime it is in user space, or
  3. Anytime the process is scheduled for execution by the scheduler

Thanks!

like image 231
Achint Mehta Avatar asked May 29 '26 04:05

Achint Mehta


1 Answers

According to http://www.tldp.org/LDP/tlk/ipc/ipc.html, the process would handle the signal when it exits from a system call. This would mean that a normal instruction like a = b+c (or its equivalent machine code) would not be interrupted because of signal.

Well, if that were the case, a CPU-intensive process would not obey the process scheduler. The scheduler, in fact, can interrupt a process at any point of time when its time quantum has elapsed. Unless it is a FIFO real-time process.

A more correct definition: One point when a signal is delivered to the process is when the control flow leaves the kernel mode to resume executing user-mode code. That doesn't necessarily involve a system call.

like image 183
Maxim Egorushkin Avatar answered May 31 '26 07:05

Maxim Egorushkin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!