Is there an overlap in the uses of PID and jobspec in Bash?

In my script I store the PID of a command in a variable using $!. Then I call disown with the PID to remove the job from the shell's active jobs table. Later the script may or may not kill the process using kill depending on circumstances. The purpose of this is so that unsightly 'job killed' messages do not appear in the terminal and make my script's neat output look unsightly.

It works fine, but I am confused by the difference between PID and jobspec, because...

$! - the PID of the most recent background command.
disown [-ar] [-h] [jobspec ...]
kill [-s sigspec | -n signum | -sigspec] [pid | jobspec]

disown requires a jobspec, but I am giving it a PID. man bash says that disown returns 0 unless jobspec does not specify a valid job. I give it a PID and it returns 0, so all seems ok.

A search through man bash for jobspec makes no mention that a PID can be used instead of a jobspec in general and the disown entry does not say a PID can be used instead of a jobspec.

PID and jobspec are not the same thing, but is there an overlap in their use? If not then why does my code work? Is it as simple as disown being able to take a PID instead of a jobspec and that this is not documented in man bash?



choroba is correct, disown being able to take a PID instead of a jobspec does seem to be an undocumented feature of disown. I have now confirmed this with tests on 2 different versions of GNU Bash.

GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu) [On Linux Mint]
GNU bash, version 4.3.30(1)-release (x86_64-pc-linux-gnu) [On Debian]

Although not documented by GNU (as far as I can tell), it is documented by the Linux Documentation Project, in the 3rd sentence on their Job Control Commands page.

I emailed the maintainer of the GNU Bash man page suggesting that the disown entry in the shell builtin commands section be changed:

From: disown [-ar] [-h] [jobspec ...]
To:   disown [-ar] [-h] [jobspec | pid] ...

He has now confirmed the error and has made the change.

  • 1
    The GNU Bash man page maintainer has confirmed that the documentation is wrong and that he will be changing it to read: disown [-ar] [-h] [jobspec | pid] HTH. – mattst Nov 26 '15 at 21:46

It seems like an undocumented feature of disown. Bash can't mistake a PID for a jobspec, as jobspec always starts with a %.

| improve this answer | |
  • Thanks. See edit of my question (to much to add in a comment). – mattst Nov 19 '15 at 13:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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