help-bash
[Top][All Lists]
Advanced

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

[Help-bash] Backgrounded commands and wait


From: DJ Mills
Subject: [Help-bash] Backgrounded commands and wait
Date: Wed, 27 Mar 2013 17:33:05 -0400

When you fork a command with "&", but do not use "wait", will bash call wait(3) when the command terminates? In other words, will the PID possibly be reused before the shell exits?

For example:
some_command & pid=$!; { sleep 10; kill "$pid"; } &

If "some_command" completes before sleep, is it possible that the PID could be reused before "kill" executes? That could get quite nasty. I wouldn't think that would be the case because you could theoretically use ''wait "$pid"'' 10 lines later, and would still need to get the correct exit status. I'm just looking for confirmation, couldn't find it in the docs.

Thanks,
DJ

reply via email to

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