2

We recently discovered that GNU kill, going beyond spec, will take a name as its argument and try to kill all processes with that name, in the same vein as pkill(1) or some implementations of killall.

I haven't been able to find GNU's changelog for kill. When was that "feature" added?

kojiro
  • 4,644
  • Neither my builtin kill nor /bin/kill ("procps version 3.2.8") accept a name...? – Kevin Nov 28 '11 at 22:39
  • @Kevin thanks for the feedback. I added a link to the manpage that matches the version of kill I'm dealing with. (If I read that correctly the feature was introduced by Salvatore Valente, which I didn't notice before. I suppose I could email him, but that seems presumptuous when there must be a changelog out there somewhere.) – kojiro Nov 28 '11 at 22:51
  • 2
    the man page you have mentioned is man page for bsd kill and not for gnu kill. – Sachin Divekar Nov 28 '11 at 22:55
  • From FreeBSD 2.1 killall does that. (It does something different on Solaris, and make *sure* you understand the difference!) – dmckee --- ex-moderator kitten Nov 28 '11 at 23:18
  • 3
    @SachinDivekar It's not BSD kill either. That particular implementation of kill is specific to Linux, and the feature doesn't seem to have existed on classic BSD either (e.g. 4.4BSD). – Gilles 'SO- stop being evil' Nov 28 '11 at 23:19
  • 1
    @Gilles, yes you are right. I checked the man page again. It says Linux Utilities at the bottom left. Plus in AUTHER section it is mentioned that Taken from BSD 4.4. The ability to translate process names to process ids was added by Salvatore Valente. So, the man page is for Linux and it is taken and updated from BSD 4.4 version. – Sachin Divekar Nov 28 '11 at 23:26
  • Indeed, I would expect a BSD version of kill to behave the same as the kill on OS X. The kill in question does not. – kojiro Nov 28 '11 at 23:27

1 Answers1

8

You can browse the source of Gnu coreutils on Savannah (or clone the repository on your machine), and in particular look at the source and the changelog of the kill utility. There is not and has never been such a feature.

do {
      intmax_t n = (errno = 0, strtoimax (arg, &endp, 10));
      …
      if (errno == ERANGE || pid != n || arg == endp || *endp)
        {
          error (0, 0, _("%s: invalid process id"), arg);
          status = EXIT_FAILURE;
        }
      …
} while ((arg = *++argv));

The manpage you link to is for the kill command from the util-linux collection. As you can see from the date of the man page, this feature is very old. Many Linux systems ship the kill command from GNU coreutils, or the one from the procps package, and most of the time you'll see your shell's builtin rather than the external command anyway. None of these allow you to pass a bare command name as an argument.

On a related note, in bash, ksh and zsh, you can pass any job specification as an argument to kill. Job specifications start with a % and can be followed by a job number or by a part of the name of the command of that job.

$ jobs
[3] +  Running                 sleep 9999 &
[2] - Stopped                  vim foo
[1]    Running                 xterm &
$ kill %sleep
[3] + Terminated               sleep 9999 &
$ jobs
[2] + Stopped                  vim foo
[1] -  Running                 xterm &
  • 1
    What happened here is that someone used sudo kill java when he meant to do sudo killjava (where killjava is a local script). Sudo bypassed the shell builtin, and I was trying to figure out why /bin/kill behaved differently. I'm surprised, but pleased, to discover that GNU was not the culprit this time. – kojiro Nov 28 '11 at 23:23