Junior — Middle
Explain what signals in the Unix operating system are and how they are used for inter-process communication.
sobes.tech AI
Answer from AI
In Unix systems, signals are a mechanism for asynchronous notification of processes about events. A signal is a short message sent to a process by the kernel or another process to inform it about an event.
Examples of signals:
- SIGINT — interrupt (usually Ctrl+C)
- SIGTERM — request to terminate the process
- SIGKILL — immediate termination of the process
- SIGSTOP — pause the process
Signals are used for:
- Process management (termination, suspension, resumption)
- Error handling (for example, division by zero triggers SIGFPE)
- Inter-process communication (for example, one process can send a signal to another for synchronization)
A process can set a signal handler to perform specific actions upon receiving a signal, or ignore the signal (if permitted).
Example of using a signal in shell:
kill -SIGTERM <pid> # Send termination signal to the process with ID pid
Thus, signals are a simple and effective way to interact with and manage processes in Unix.