Ways to Kill a Process

Download Ways to Kill a Process

Post on 06-Apr-2018




0 download

Embed Size (px)


<ul><li><p>8/2/2019 Ways to Kill a Process</p><p> 1/2</p><p>Ways to Kill a Process kill, killall, pkill, xkill</p><p>Kill command is use to send signal to a process or to kill a process. We typically use kill -</p><p>SIGNAL PID, where you know the PID of the process.</p><p>There are other ways to effectively kill a process killing a process by name, killing a</p><p>process by specifying part of the name, killing a process by pointing out the process with</p><p>cursor etc.,</p><p>1. Kill Command Kill the process by specifying its PID</p><p>All the below kill conventions will send the TERM signal to the specified process. For the</p><p>signals, either the signal name or signal number can be used. You need to lookup the pid</p><p>for the process and give it as an argument to kill.</p><p>$ kill -TERM pid</p><p>$ kill -SIGTERM pid</p><p>$ kill -15 pid</p><p>Example: Kill the firefox process.</p><p>$ ps -ef | grep firefox</p><p>1986 ? Sl 7:22 /usr/lib/firefox-3.5.3/firefox</p><p>$ kill -9 1986</p><p>2. Killall Command Kill processes by name</p><p>Instead of specifying a process by its PID, you can specify the name of the process. If</p><p>more than one process runs with that name, all of them will be killed.</p><p>Example: Kill all the firefox processes</p><p>$ killall -9 firefox</p><p>3. Pkill Command Send signal to the process based on its name</p><p>You can send signal to any process by specifying the full name or partial name. So there</p><p>is no need for you to find out the PID of the process to send the signal.</p><p>Example: Send SIGTERM to all the process which has sample in its name.</p></li><li><p>8/2/2019 Ways to Kill a Process</p><p> 2/2</p><p>$ pkill sample</p><p>Pkill Example:</p><p>Before sending signal, you can verify which are all the process is matching the criteria</p><p>using pgrep -l, which displays the process ID and process name of the matchingprocesses.</p><p>In this example, all the processes are designed to log the signal to signal-log, along with</p><p>its PID.</p><p>$ pgrep -l sample</p><p>12406 sample-server.p</p><p>12425 sample-server.p</p><p>12430 sample-garbagec</p><p>$ pkill -USR1 sample</p><p>$ cat signal-log</p><p>Name: ./sample-server.pl Pid: 12406 Signal Received: USR1</p><p>Name: ./sample-server.pl Pid: 12425 Signal Received: USR1</p><p>Name: ./sample-garbagecollector.pl Pid: 12430 Signal Received: USR1</p><p>Note: The part of name which you specify should be in the character within the first 15</p><p>character of the process name.</p><p>4. Xkill Command kill a client by X resource</p><p>xkill is the simplest way to kill a malfunctioning program. When you want to kill a</p><p>process, initiate xkill which will offer an cross-hair cursor. Click on the window with left</p><p>cursor which will kill that process.</p><p>$ xkill</p><p>Select the window whose client you wish to kill with button 1....</p><p>xkill: killing creator of resource 0x1200003</p><p>Note: Actually, xkill instructs XServer to terminate the client.</p></li></ul>