[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: pkill

From: Eric Blake
Subject: Re: pkill
Date: Thu, 29 Sep 2005 22:39:24 +0000

>    Remember, POSIX requires kill(1) to be a shell builtin, because it
>    must support job syntax ("kill %1", for example), which cannot be
>    done with normal POSIX child process semantics.
> In that case, one can make the builtin kill a wrapper, that parses the
> command line, and if it see %1 it replaces it with the process job pid
> and passes that to the real kill, or the builtin kill if no system
> kill utiltiy exists.

Write your own shell function that does just that.  You can
use 'jobs -p' to find the process number.  Something like
this untested snippet (making it robust to arbitrary input
and arbitrary number of arguments is left an exercise to
the reader):

  for arg in "$*" ; do
    case $arg in
      %*) arglist="$arglist `jobs -p $arg`" ;;
      *) arglist="$arglist $arg" ;;
  test -x /bin/kill && /bin/kill $arglist || builtin kill $arglist

> Just cause POSIX says something, doesn't mean that it is right.

True.  But in this case, it doesn't make it wrong, either.  Another
argument for making kill a builtin is if you hit your ulimit on max
processes, builtin kill will work, but trying an external kill will fail.

Eric Blake

reply via email to

[Prev in Thread] Current Thread [Next in Thread]