kill: SIGSTOP: invalid signal specification error in bash script

The standard (POSIX) syntax is:

kill -s STOP "$pid"

That is, without the SIG prefix. Some shell implementations, support kill -s SIGSTOP or kill -SIGSTOP as an extension but that's not standard nor portable.

The UNIX specification (POSIX+XSI) also allows:

kill -STOP "$pid"

And

kill -19 "$pid"

Though which signal number is SIGSTOP is not specified and may change between systems and even architectures for a same system, so should be avoided.


To start with: SIGSTOP will temporarily stop the process but keep in memory so it can be continued later on using SIGCONT system call. You can use the following little snippet to see what happens

#!/bin/bash

set -x

sleep 100 &
pid=$!
kill -s SIGSTOP "$pid"
sleep 2
kill -s SIGCONT "$pid"

You'll see what the script does interactively.

So to get your script working using #/bin/sh shebang you'd do something like

#!/bin/sh

set -x
set +o posix
sleep 100 &
pid=$!
kill -s SIGSTOP "$pid"
sleep 2
kill -s SIGCONT "$pid"
set -o posix

I am facing the same problem. All answers here did not address the true cause of the issue. Inside the script the kill used is the built-in provided by the shell, that is why you are having the error. While in your terminal, the kill used is the separate executable located at /bin/kill. To fix the issue, inside your script you must explicitly use the /bin/kill and not the built-in shell version. Therefore you write it like this:

#!/bin/sh
/bin/kill -s SIGHUP 14344