Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
kill -TERM -PID 

is supposed to kill PID and all its child processes.
but this doesn't work on openSUSE, it always tell me that no such process -PID no matter what PID i use.
So if the negative PID option is not supported by this particular version of kill, what is the best way to kill a group of processes?

I have a shell script running. inside the script, I use wget to download things. So the script is the parent process, wget is the child process. I want to kill them both using kill -TERM -PID_OF_SCRIPT

share|improve this question
Quoting the standard: If the first pid operand is negative, it should be preceded by "--" to keep it from being interpreted as an option. Also, using a negative number for the pid arg actually refers to the process group ID. – Totor Mar 22 '13 at 13:40
It's not supposed to kill PID and all its child processes, it's supposed to kill all the processes of pgid PID. Use ps -j to see the process group ids. – Stéphane Chazelas Feb 20 '14 at 16:11
up vote 6 down vote accepted

Does it say "no such PID" or is there an error, - as in does this work?

kill -TERM -- -GPID

Also note, as per (emphasize mine)
man 1:

"[…] When an argument of the form '-n' is given, and it is meant to denote a process group […]"

man 2:

"[…] If pid is less than -1, then sig is sent to every process in the process group whose ID is -pid. […]"

man 3:

"[…] If pid is negative, but not -1, sig shall be sent to all processes (excluding an unspecified set of system processes) whose process group ID is equal to the absolute value of pid, […]"

As in, not PID but process group ID.

Else perhaps you can have so fun with /proc/[pid]/stat

ppid: awk '{gsub(/\([^)]+\)/,"_"); print $4}' /proc/3955/stat
pgrp: awk '{gsub(/\([^)]+\)/,"_"); print $5}' /proc/3955/stat

pkill -TERM -g PGRP

share|improve this answer
it says /bin/kill: -23958: No such process. – David Dai Mar 22 '13 at 9:00
pkill -TERM -g PGRP, this works perfectly in my case. – David Dai Mar 22 '13 at 9:12

The error message /bin/kill: -23958: No such process may also be due to the fact that the pid 23958 is no pgid (process group id number)!

This can, for example, be the case if you try to kill a backgrounded shell (or command) in a script mistakenly using $! as a pgid; in a job-control enabled shell, however, $! can be used as a pgid (see: Why child process still alive after parent process was killed in Linux?).

# examples of how to kill a process group
# (using sh -c '...' instead of a shell script)

# kill: -<num>: No such process
sh -c '
(sleep 200 & sleep 200 & sleep 200) &
/bin/kill -s TERM -$!

# in Terminal.app 
# job control is enabled by default
(sleep 200 & sleep 200 & sleep 200) &
/bin/kill -s TERM -$!

# enable job control
sh -c '
set -m 
(sleep 200 & sleep 200 & sleep 200) &
/bin/kill -s TERM -$!

# make sure pid == pgid
# note that the script gets killed as well
sh -c '
echo pid $$
trap "trap - EXIT; echo pid $$ was killed" EXIT
(sleep 200 & sleep 200 & sleep 200) &
IFS=" " read -r pgid <<EOF
$(ps -p $! -o pgid=)
sleep 5
/bin/kill -s TERM -${pgid}
sleep 5
echo pid $$ was not killed

# use a pseudo-terminal (pty) to avoid killing the script
# note the use of -$$ instead of -$!
sh -c '
echo pid $$
script -q /dev/null sh -c '\''
trap "" HUP
(sleep 200 & sleep 200 & sleep 200) &
sleep 5
/bin/kill -s TERM -$$
sleep 5
echo pid $$ was not killed
share|improve this answer

You could use the "pkill" or the "killtree" solution, shown on this thread on other of the StackExchange sites :)


share|improve this answer

This may have to do with you using the shell built-in kill and not the binary, try to use


If it works I would suggest to check if your shell has added the process group feature to a newer version. Or just use the binary.

share|improve this answer
I thought about that. And I tried /bin/kill, it didn't help. – David Dai Mar 22 '13 at 8:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.