Linux Commands Examples

A great documentation place for Linux commands

kill

send a signal to a process


see also : killall - nice - pkill - renice - skill

Synopsis

kill [options] <pid> [...]


add an example, a script, a trick and tips

: email address (won't be displayed)
: name

Step 2

Thanks for this example ! - It will be moderated and published shortly.

Feel free to post other examples
Oops ! There is a tiny cockup. A damn 404 cockup. Please contact the loosy team who maintains and develops this wonderful site by clicking in the mighty feedback button on the side of the page. Say what happened. Thanks!

examples

0

kill -9 -1

Kill all processes you can kill.

kill -l 11

Translate number 11 into a signal name.

kill -L

List the available signal choices in a nice table.

kill 123 543 2341 3453

Send the default signal, SIGTERM, to all those processes.


0
In my ~/.bashrc file, I have added the following function :



function k(){

 ps aux | grep $1 | tr -s ' ' | cut -f2 -d" " | xargs kill -9

}



then, whenever I use the command line, I can do :

k <name of software>

so :

k firefox # kills all instances of firefox, including some processes that are related

k netbeans # kills all instances of netbeans



of course, the 9 signal force the shutdown abruptly,and should only be used when you can't close a software or process, normaly.
example added by LeBerger
0
In my ~/.bashrc file, I have added the following function :



function k(){

 ps aux | grep $1 | tr -s ' ' | cut -f2 -d" " | xargs kill -9

}



then, whenever I use the command line, I can do :

k <name of software>

so :

k firefox # kills all instances of firefox, including some processes that are related

k netbeans # kills all instances of netbeans



of course, the 9 signal force the shutdown abruptly,and should only be used when you can't close a software or process, normaly.
example added by LeBerger
0
source
            
kill 21391
kill 21392
0
source
            
kill 5853
kill 5854
kill 5855
kill 5856
0
source
            
kill 10294
0
source
            
kill 3012
0
source
            
kill 27789
0
source
            
kill 5176
0
source
            
kill 3588
0
source
            
kill 22671
0
source
            
kill 4616
0
source

How do you find the parent process of a zombie process?

Add the l option to your ps command line. This is the option for long output. The parent process id is one of the additional columns -- labeled PPID.

$ ps l
F   UID   PID  PPID PRI  NI    VSZ   RSS WCHAN  STAT TTY        TIME COMMAND
0   508  3344  4498  18   0   2452  1236 wait   Ss   pts/12     0:00 /bin/sh
0   508  4467 17796  15   0   4664  1572 wait   Ss   pts/5      0:00 -/bin/bash
0   508  4498  4467  15   0  23032 15108 -      S+   pts/5      2:20 emacs -nw
0   508  4532 17796  15   0   4532  1464 wait   Ss   pts/13     0:00 -/bin/bash
0   508  4916 17796  15   0   4664  1648 wait   Ss   pts/7      0:01 -/bin/bash

Another option is the pstree command to show an ascii tree representation of the processes. You'll probably want the -p option to show process ids.

$ pstree -p dharris
screen(17796)???bash(4467)???emacs(4498)???sh(3344)???sh(3345)
              ??bash(4532)???su(31037)???bash(31041)
              ??bash(4916)???pstree(26456)
              ??bash(13547)???su(20442)???bash(20443)
              ??bash(17797)

sshd(25813)???bash(25817)???screen(25870)

0
source

How to kill a process started with a different user without being root or sudoer?

No, you can't.

If you want to share processes with other users, you should start the process under a common user id.

0
source

killall shenanigans

next time, when you killed everything (and are sitting in front of the physical box), hold the Alt and SysRQ (PrintScreen) keys, and type U S B. That means, Unmount, Sync and re**B**oot. That will at least make sure that unflushed changes in the filesystem get onto your disks.

For now, boot your system in single user mode and try to run fsck manually (maybe with -f option). Then examine your lost+found and delete anything you are sure you don't need any longer.

0
source

kill -9 programs but they still hang on

It does mean using kill -15 PID (or another number) instead of kill -9 PID. The numbers are equivalent to different unix signals.

0
source

What to do if kill -9 doesn't work?

When a process remains in the process table as this process has, then you need to kill its parent process. First, find the parent process PID:

ps -eo 'pid,ppid,comm' | grep 97442

Then run kill <pid> for whatever the ppid result is. (Give it a chance to die cleanly, first.)

The traditional Unix design keeps process information around for the parents to reap and clean up, in case the parent processes want to run getrusage(2) to find out the resource usage of its children, or wait(2) for their exit status, etc.

When parents don't reap their children, the children remain zombies -- UNTIL the parent process is killed, at which point the kernel will re-parent the children to init(8). init(8) will reap the newly re-parented children.

0
source

What killed my process?

SystemTap looks like it can't find the debug symbols for your kernel. Have you installed the required kernel debug packages for the kernel you are running? The SystemTap guide says:

To deploy SystemTap, you need to install the SystemTap packages along with the corresponding set of -devel, -debuginfo and -debuginfo-common packages for your kernel. If your system has multiple kernels installed, and you wish to use SystemTap on more than one kernel kernel, you will need to install the -devel and -debuginfo packages for each of those kernel versions.

0
source

Can't kill a sleeping process

You could try killing the parent process. Use ps to check:

ps xjf -C yum

Then kill -9 any parent processes.

0
source

When a python process is killed on OSX, why doesn't it kill the child processes?

On linux, when you kill a parent the child gets sent a sighup which will generally kill it unless it was meant to stay alive as a daemon in which case it will trap sighup. (I think this is why one usually uses sighup to tell a daemon to refresh itself, since it's conveneintly always trapped). On macosx I can't find documentation but it appears that no sighup gets sent. As a result the child process is orphaned and it's new parent is the grandparent. The way you deal with this is you send the kill signal to the process group of the parent not the parent process itself. This will nuke all the children and grand children as well with one caveate. If any child process does a setpgrp() or setsid() then it escapes the process group membership. It will not get the kill sent to it's old process group. Usually one need not worry about the latter since it's usually intentional when used to achieve that purpose.

0
source

How do I kill a process by its name in Linux?

killall bla

to force it:

killall -9 bla

0
source

Bash operator < , > , | and grep / kill

Try

kill `ps -A | grep nautilus | egrep -o '[0-9]{4,5}'`

The commands within the backticks will be executed and fed as a part of the command.

0
source

How to kill a process with name having spaces?

You don't need to give killall the complete command line; killall valgrind would be sufficient in your case.

~$ perl -e 'sleep 10000' &
[1] 3586
~$ ps ax | grep perl
 3586 pts/3    S      0:00 perl -e sleep 10000
 3588 pts/3    S+     0:00 grep perl
~$ killall perl
[1]+  Terminated              perl -e 'sleep 10000'
~$ 

0
source

How an unprivileged user could kill a process she didn't start?

Oracle runs its SID sub-processes as Real UID of database owner (hri here), while the Effective UID is Oracle's (oracle). Which is why hri was able to kill what was actually its own processes.

You can use ps axf -O ruid,ruser,euid,euser to display side-by-side both RUID and EUID.

0
source

What does kill 0 do actually?

The issue is not with 'kill 0', which works as expected, but with the fact that the target process is stopped.

Try this:

kill -9 0

0
source

Kill bash processes "nicely"

Your soft_kill has a few issues.

  • killing a process isn't instantaneous but kill exits as soon as the signal is sent. You'll have to wait for a while before determining if the kill command succeed or if you need to escalate to -INT or -HUP.
  • kill returns(1) zero (success) if it's allowed to send the signal. Not if it succeeds to kill the process. So in your code only the first kill will be executed.

(1)

kill()
RETURN VALUES
If successful, kill() returns a value of zero. On failure, it returns a value of -1, does not send a signal, and sets errno to one of the following values:

EINVAL
The value of sig is an invalid or unsupported signal number.

EPERM
The user ID of the sending process is not privileged; its real or effective user ID does not match the real or saved user ID of the receiving process. Or, the process does not have permission to send the signal to any receiving process.

ESRCH
No process or process group can be found that corresponds to the one that pid specifies.

description

The default signal for kill is TERM. Use -l or -L to list available signals. Particularly useful signals include HUP, INT, KILL, STOP, CONT, and 0. Alternate signals may be specified in three ways: -9, -SIGKILL or -KILL. Negative PID values may be used to choose whole process groups; see the PGID column in ps command output. A PID of -1 is special; it indicates all processes except the kill process itself and init.

options

<pid> [...]

Send signal to every <pid> listed.

-<signal>
-s <signal>
--signal <signal>

Specify the signal to be sent. The signal can be specified by using name or number. The behavior of signals is explained in signal(7) manual page.

-l, --list [signal]

List signal names. This option has optional argument, which will convert signal number to signal name, or other way round.

-L--table

List signal names in a nice table.

notes

Your shell (command line interpreter) may have a built-in kill command. You may need to run the command described here as /bin/kill to solve the conflict.

reporting bugs

Please send bug reports to procps[:at:]freelists[:dot:]org (procps[:at:]freelists[:dot:]org)

standards

This command meets appropriate standards. The -L flag is Linux-specific.


see also

kill, killall , nice , pkill , renice , signal, skill


author

Albert Cahalan (albert[:at:]users.sf[:dot:]net) wrote kill in 1999 to replace a bsdutils one that was not standards compliant. The util-linux one might also work correctly.

How can this site be more helpful to YOU ?


give  feedback