Introduction to Signals
- A signal is used to notify a process that an event has occurred.
- Sometimes called software interrupts
- Processes can, if given permission, send signals to other processes.
- This is used by the shell to kill background jobs.
- This can be a primitive form of inter process communications.
- It is normal, however for signals to be generated by the kernel.
- A hardware exception occurred.
- An illegal instruction
- A floating point exception
- The user typed one of the special characters that generates a signal
- ctrl-c: interrupt
- ctrl-z: suspend
- A software event occurred
- SIGCHILD, timer, IO change, ...
- Signals are a small, unique integer
- man 7 signal
- They are not UNIVERSAL across unix/linux implementations.
- Some are everywhere (1-9 or so) others are not.
- In general
- An event causes a signal to be generated
- It is then delivered to a process
- A signal is pending between the time it is generated and the time it is delivered.
- Usually pending signals are acted upon immediately when the process runs next.
- The process may block some signals.
- Or the process may handle the signal.
- Some signals my not be blocked or handled
- By default signals , depending on the signal
- Cause the program to terminate or exit
- Cause the program to dump core and exit.
- on most linux systems core dumps are set to 0 by default.
- ulimit -c size
- ulimit -c unlimited
- ulimit -c 0
- Cause the program to suspend
- Cause a suspended program to resume
- Are ignored
- Default actions can be overridden by a signal handler
- Signal handlers are installed
- when a signal handler is called the signal is caught
- Some signals can't be caught, blocked, or ignored
- SIGSTOP - suspend the process
- SIGKILL - cause the process to exit
- There is a full list of signals
- In the book, pages 390 - 395
- man 7 signal
- Some important signals are
- SIGHUP (1) - hangup
- SIGINT - interrupt from keyboard
- SIGKILL (9) - kills processes dead
- SIGCHLD - child termination
- SIGUSR1, SIGUSR2 - reserved for user signals.
- The numbers differ on different architectures.
- The numbers are just numbers, there is no priority.
- Sending a signal to a process (command line)
- /bin/kill and the bash builtin kill
- kill signal pid
- kill -9 12345
- kill -KILL 12345
- Best to use -1 first then -9
- Many processes catch -1 (HUP) and clean up
- Editors will save the current version in a backup file
- Others might close log files.
- In bash %n corresponds to the number assigned to background processes.
- Play with usr.C