Questions tagged [signals]

A signal is a message which can be sent to a running process. Signals can be initiated by programs, users, or administrators.

Handling Signals

Each Unix signal has a default set of effects on a Unix program. Programmers can code their applications to respond in customized ways to most signals. These custom pieces of code are called signal handlers.

Two signals are unable to be redefined by a signal handler. SIGKILL always stops a process and SIGSTOP always moves a process from the foreground to the background. These two signals cannot be "caught" by a signal handler.

600 questions
279
votes
4 answers

How does a Segmentation Fault work under-the-hood?

I can't seem to find any information on this aside from "the CPU's MMU sends a signal" and "the kernel directs it to the offending program, terminating it". I assumed that it probably sends the signal to the shell and the shell handles it by…
Braden Best
  • 2,183
  • 2
  • 12
  • 12
147
votes
5 answers

Forward SIGTERM to child in Bash

I have a Bash script, which looks similar to this: #!/bin/bash echo "Doing some initial work...."; /bin/start/main/server --nodaemon Now if the bash shell running the script receives a SIGTERM signal, it should also send a SIGTERM to the running…
Lorenz
  • 1,573
  • 2
  • 10
  • 5
104
votes
3 answers

How to signal the end of stdin input

In Bash, I learned that the ending signal can be changed by here document. But by default how can I signal the end of stdin input? I happened to find that with cat and chardet, their stdin inputs can be signaled as finished by Ctrl+D. But I seems…
Tim
  • 98,580
  • 191
  • 570
  • 977
102
votes
2 answers

List of terminal generated signals (eg Ctrl-C -> SIGINT)

Where can I find a complete list of the keyboard combinations which send signals in Linux? Eg: Ctrl+C - SIGINT Ctrl+\ - SIGQUIT
Tom Hale
  • 28,728
  • 32
  • 139
  • 229
95
votes
9 answers

How can I check what signals a process is listening to?

How can I verify whether a running process will catch a signal, or ignore it, or block it? Ideally I'd like to see a list of signals, or at least not have to actually send the signal to check.
Jander
  • 16,272
  • 6
  • 50
  • 66
91
votes
7 answers

"trap ... INT TERM EXIT" really necessary?

Many examples for trap use trap ... INT TERM EXIT for cleanup tasks. But is it really necessary to list all the three sigspecs? The manual says: If a SIGNAL_SPEC is EXIT (0) ARG is executed on exit from the shell. which I believe applies whether…
musiphil
  • 1,601
  • 2
  • 14
  • 15
85
votes
1 answer

List of Kill Signals

I'm familiar with several process signals and what they do, but I would like to understand them all. There are three things I would like to find out about each signal. What the signal does When a signal like this is typically sent Any command line…
Dave
  • 975
  • 1
  • 7
  • 5
82
votes
4 answers

Default exit code when process is terminated?

When a process is killed with a handle-able signal like SIGINT or SIGTERM but it does not handle the signal, what will be the exit code of the process? What about for unhandle-able signals like SIGKILL? From what I can tell, killing a process with…
Cory Klein
  • 18,391
  • 26
  • 81
  • 93
81
votes
5 answers

Why is SIGINT not propagated to child process when sent to its parent process?

Given a shell process (e.g. sh) and its child process (e.g. cat), how can I simulate the behavior of Ctrl+C using the shell's process ID? This is what I've tried: Running sh and then cat: [user@host ~]$ sh sh-4.3$ cat test test Sending SIGINT to…
rob87
  • 813
  • 1
  • 7
  • 6
77
votes
11 answers

Terminating an infinite loop

I have a command that I want to have run again automatically each time it terminates, so I ran something like this: while [ 1 ]; do COMMAND; done; but if I can't stop the loop with Ctrl-c as that just kills COMMAND and not the entire loop. How…
howard
  • 1,332
  • 1
  • 11
  • 16
73
votes
11 answers

How to stop the loop bash script in terminal?

For example, #!/bin/bash while : do sl done How to terminate this bash script?
Yinyanghu
  • 843
  • 1
  • 7
  • 5
61
votes
7 answers

Timing out in a shell script

I have a shell script that's reading from standard input. In rare circumstances, there will be no one ready to provide input, and the script must time out. In case of timeout, the script must execute some cleanup code. What's the best way to do…
Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
54
votes
9 answers

Unable to stop a bash script with Ctrl+C

I wrote a simple bash script with a loop for printing the date and ping to a remote machine: #!/bin/bash while true; do # *** DATE: Thu Sep 17 10:17:50 CEST 2015 *** echo -e "\n*** DATE:" `date` " ***"; echo…
nephewtom
  • 703
  • 1
  • 5
  • 10
50
votes
1 answer

Difference between less violent kill signal -HUP (1) -INT (2) and -TERM (15)

Apart from the most violent kill -9 (SIGKILL), I don't quite understand the difference between the 3 other common signals (here) -HUP (1), -INT (2), and -TERM (15). In which scenarios would one work and the other not? In general when does -9…
Kenny
  • 1,525
  • 6
  • 18
  • 25
48
votes
1 answer

What does a program do when it's sent SIGKILL signal?

When I used killall -9 name to kill a program, the state become zombie. Some minutes later, it stopped really. So, what's happening during those minutes?
haikun he
  • 583
  • 1
  • 4
  • 4
1
2 3
39 40