Re: jobs in scripts?

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

 



Thanks. Well, I am currently using PIDs, $!, kill $pid and kill --
-$pgrp. However, I noticed that **even if I don't wait** for a
background job, the shell somehow auto-reaps dead children:

$ dash -c 'sleep 1 & echo "PID $!"; sleep 1000' &
[1] 7840
PID 7841
$ ps ax | grep [7]841
$

So, since dead children get reaped (instead of becoming zombies for a
while), their PIDs are not "reserved". After a PID wrap-around at
32767, a different process could get the same PID. That makes PIDs
unreliable. I could end up killing a completely unrelated process,
instead of a (possibly zombified) child.

That's why I thought I'd try to see if "jobs" could work more reliably.

> That much is clear. However, "kill" and "jobs -p" are less clear. Their

I only need plain "jobs"... I used "jobs -l" as a convenience in the
example I gave, but plain "jobs" would be enough.

Unfortunately, it seems the "kill %n" does indeed refer to process
groups. I didn't realize this means the shell is not guaranteed to
support "kill %n" unless "set -m" is in effect (and, again, there are
problems with set -m in dash).


-- Dan
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux