

The previous example traps the signals 1, 2, 3, and 15, and executes the /bin/rm tmp$$ command before exiting the program.

#Psef command how to
Here's an example of how to trap a signal in a script: # trap '/bin/rm tmp$$ exit 1' 1 2 3 15Īs the name suggests, trap traps system interrupt until some command can be executed. Thus, kill -9 invites corruption of application data files and should only be used as a last resort.
#Psef command install
Because the process cannot install a signal handler for signal 9, an otherwise well-behaved process may leave temporary files around or not be able to finish out critical operations that it is in the middle of. Signal handlers cannot be installed for SIGSTOP (23) or SIGKILL (9).
#Psef command update
This signal can then be used to update the process while running, without having to terminate and restart the process. For example, many system programs, such as the name server daemon, respond to the SIGHUP signal by re-reading their configuration files. In addition, you can write a signal handler, or trap, in a program to respond to a signal being sent. Obtain a list of the signals by typing: man signal.h Inter-LWP signal reserved by threads library.Ĭancellation signal reserved by the threads library. A gentle kill that gives processes a chance to clean up.Ĭoncurrency signal reserved by threads library. Informs a process of a floating-point error. Quits the process and produces a core dump.Īrithmetic exception.

The user can generate this signal by pressing Ctrl+C or Delete. Usually means that the controlling terminal has been disconnected. Finally, if you need to kill the process, you can do it via: kill -9 `cat save_pid.Don't worry about remembering all of the signals listed just be familiar with the more common signals, such as SIGHUP, SIGKILL, SIGSTOP, and SIGTERM. If the command sends output on a regular basis, you can check the output occasionally with tail my.log, or if you want to follow it "live" you can use tail -f my.log. See I/O Redirection for more details on handling I/O redirection with the shell. The 2>&1 is needed to capture any error messages that normally are written to standard error into our my.log file (which is coming from standard output). It requires &1 so that the shell knows it's a file descriptor in that context instead of just a file named 1. The 2 is the file descriptor for standard error ( stderr) and 2>&1 tells the shell to route standard error output to the standard output (file descriptor 1). This will run my_command saving all output into my.log (in a script, $! represents the PID of the last process executed). If you use a script, you could do something like this in the script: nohup my_command > my.log 2>&1 & Note that nohup keyword/command itself does not appear in the ps output for the command in question. Alternatively, you can find the PID later on by ps -ef | grep "command name" and locate the PID from there. If your plan is to manually manage the process, you can save that PID and use it later to kill the process if needed, via kill PID or kill -9 PID (if you need to force kill). When using nohup and you put the task in the background, the background operator ( &) will give you the PID at the command prompt.
