24.07.2018 Views

Bash-Beginners-Guide

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Bash</strong> <strong>Guide</strong> for <strong>Beginners</strong><br />

Ctrl+Y<br />

Ctrl+Z<br />

The delayed suspend character. Causes a running process to be stopped when it attempts to<br />

read input from the terminal. Control is returned to the shell, the user can foreground,<br />

background or kill the process. Delayed suspend is only available on operating systems<br />

supporting this feature.<br />

The suspend signal, sends a SIGTSTP to a running program, thus stopping it and returning<br />

control to the shell.<br />

Terminal settings<br />

Check your stty settings. Suspend and resume of output is usually disabled if you are using "modern"<br />

terminal emulations. The standard xterm supports Ctrl+S and Ctrl+Q by default.<br />

12.1.2. Usage of signals with kill<br />

Most modern shells, <strong>Bash</strong> included, have a built-in kill function. In <strong>Bash</strong>, both signal names and numbers are<br />

accepted as options, and arguments may be job or process IDs. An exit status can be reported using the -l<br />

option: zero when at least one signal was successfully sent, non-zero if an error occurred.<br />

Using the kill command from /usr/bin, your system might enable extra options, such as the ability to kill<br />

processes from other than your own user ID and specifying processes by name, like with pgrep and pkill.<br />

Both kill commands send the TERM signal if none is given.<br />

This is a list of the most common signals:<br />

Table 12-2. Common kill signals<br />

Signal name Signal value Effect<br />

SIGHUP 1 Hangup<br />

SIGINT 2 Interrupt from keyboard<br />

SIGKILL 9 Kill signal<br />

SIGTERM 15 Termination signal<br />

SIGSTOP 17,19,23 Stop the process<br />

SIGKILL and SIGSTOP<br />

SIGKILL and SIGSTOP can not be caught, blocked or ignored.<br />

When killing a process or series of processes, it is common sense to start trying with the least dangerous<br />

signal, SIGTERM. That way, programs that care about an orderly shutdown get the chance to follow the<br />

procedures that they have been designed to execute when getting the SIGTERM signal, such as cleaning up<br />

and closing open files. If you send a SIGKILL to a process, you remove any chance for the process to do a tidy<br />

cleanup and shutdown, which might have unfortunate consequences.<br />

But if a clean termination does not work, the INT orKILL signals might be the only way. For instance, when a<br />

process does not die using Ctrl+C, it is best to use the kill -9 on that process ID:<br />

maud: ~> ps -ef | grep stuck_process<br />

maud 5607 2214 0 20:05 pts/5 00:00:02 stuck_process<br />

Chapter 12. Catching signals 138

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!