The kill
command is a very simple wrapper to the kill
system call, which knows only about process IDs (PIDs). pkill
and killall
are also wrappers to the kill
system call, (actually, to the libc library which directly invokes the system call), but can determine the PIDs for you, based on things like, process name, owner of the process, session id, etc.
How pkill
and killall
work can be seen using ltrace
or strace
on them. On Linux, they both read through the /proc
filesystem, and for each pid (directory) found, traverses the path in a way to identify a process by its name or other attributes. How this is done is technically speaking, kernel and system specific. In general, they read from /proc/<PID>/stat
which contains the command name as the 2nd field. For pkill -f
and pgrep
examine the /cmdline
entry for each PID's proc entry.
pkill
and pgrep
use the readproc
system call, whereas killall
does not. I couldn't say if there's a performance difference: you'll have to benchmark that on your own.
POSIX test
(or [ ... ]
) only knows about the one with a single equal sign:
s1 = s2
True if the strings s1 and s2 are identical; otherwise, false.
But Bash accepts the double equal sign too, though the builtin help doesn't admit to that (the manual does):
$ help test | grep = -A1
STRING1 = STRING2
True if the strings are equal.
STRING1 != STRING2
True if the strings are not equal.
As for other shells, it depends. Well, particularly Dash is the stubborn one here:
$ dash -c '[ x == x ] && echo foo'
dash: 1: [: x: unexpected operator
but
$ yash -c '[ x == x ] && echo foo'
foo
$ busybox sh -c '[ x == x ] && echo foo'
foo
$ ksh93 -c '[ x == x ] && echo foo'
foo
zsh
is a bit odd here, ==
is considered a special operator, so it must be quoted:
$ zsh -c '[ x == x ] && echo foo'
zsh:1: = not found
$ zsh -c '[ x "==" x ] && echo foo'
foo
The external test
/[
utility from GNU coreutils on my Debian supports ==
(but the manual doesn't admit that), the one on OS X doesn't.
So, with test
/[ .. ]
, use =
as it's more widely supported.
With the [[ ... ]]
construct, both =
and ==
are equal (at least in Bash) and the right side of the operator is taken as a pattern, like in a filename glob, unless it is quoted. (Filenames are not expanded within [[ ... ]]
)
$ bash -c '[[ xxx == x* ]] && echo foo'
foo
But of course that construct isn't standard:
$ dash -c '[[ xxx == x* ]] && echo foo'
dash: 1: [[: not found
$ yash -c '[[ xx == x* ]] && echo foo'
yash: no such command ‘[[’
And while Busybox has it, it does't do the pattern match:
$ busybox sh -c '[[ xx == xx ]] && echo yes || echo no'
yes
$ busybox sh -c '[[ xx == x* ]] && echo yes || echo no'
no
Best Answer
To suspend a process means to make it stop executing for some time. When the process is suspended, it doesn't run, but it's still present in memory, waiting to be resumed (woken up). A process can be suspended by sending it the
STOP
signal, and resumed by sending it theCONT
signal.To kill a process means to cause it to die. This can be done by sending it a signal. There are various different signal, and they don't all cause the process to die. the
KILL
signal always does cause the process to die; some other signals typically do but the process can choose to do something different; and there are signals whose role is not to cause the process to die, for exampleSTOP
andCONT
. Note that thekill
utility and thekill
C function send a signal, which may or may not actually kill the process.To terminate a process means to cause it to die. The difference between kill and terminate is that kill generally refers specifically to sending a signal, whereas terminate usually also includes other methods such as sending the process a command that tells it to exit (if the process includes a command interpreter of some kind).