bug-bash
[Top][All Lists]
Advanced

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

Re: [PATCH] silent job monitor when 'set +m'


From: Jeff Chua
Subject: Re: [PATCH] silent job monitor when 'set +m'
Date: Sun, 8 Nov 2009 20:41:43 +0800

> On Sun, Nov 8, 2009 at 5:25 AM, Chet Ramey <chet.ramey@case.edu> wrote:

> non-interactive shells don't have job control enabled by default.  Are you
saying
> you ran a script in which you enabled job control, ran a job, turned job
control off,
>  then killed the job?

> Bash and historical versions of sh report the status of jobs in a script
> that exit as the result of being killed by a signal.  I'm not going to
> change that.

Chet,

Revisited. The previous reply to your example works fine for interactive
shell. But for a script  (non-interactive shell), the example does not work
the same. Job status are always reported even with "set +m" in the script.
...

Running the examples you gave in a "script" slightly enhanced to use "ps" to
show the processes with the following script.

$ cat /tmp/a1
#!/bin/bash
sleep 60 &
P=$!
/bin/ps Tfo "pid ppid command"
set -m
echo "\$-="$-
kill $P
/bin/ps Tfo "pid ppid command"

sleep 60 &
P=$!
/bin/ps Tfo "pid ppid command"
set +m
echo "\$-="$-
kill $P
/bin/ps Tfo "pid ppid command"



1) Case 1. Without patch.

$ /tmp/a1
  PID  PPID COMMAND
25048 25047 -bash
25774 25048  \_ /bin/bash /tmp/a1
25775 25774      \_ sleep 60
25776 25774      \_ /bin/ps Tfo pid ppid command
$-=hmB
  PID  PPID COMMAND
25048 25047 -bash
25774 25048  \_ /bin/bash /tmp/a1
25777 25774      \_ /bin/ps Tfo pid ppid command
/tmp/a1: line 8: 25775 Terminated              sleep 60
  PID  PPID COMMAND
25048 25047 -bash
25774 25048  \_ /bin/bash /tmp/a1
25778 25774      \_ sleep 60
25779 25774      \_ /bin/ps Tfo pid ppid command
$-=hB
  PID  PPID COMMAND
25048 25047 -bash
25774 25048  \_ /bin/bash /tmp/a1
25780 25774      \_ /bin/ps Tfo pid ppid command
/tmp/a1: line 16: 25778 Terminated              sleep 60



2) Case 2. With patch applied. "set +m" no longer reports job killed.
$ /tmp/a1
  PID  PPID COMMAND
25048 25047 -bash
26242 25048  \_ /bin/bash /tmp/a1
26243 26242      \_ sleep 60
26244 26242      \_ /bin/ps Tfo pid ppid command
$-=hmB
  PID  PPID COMMAND
25048 25047 -bash
26242 25048  \_ /bin/bash /tmp/a1
26245 26242      \_ /bin/ps Tfo pid ppid command
/tmp/a1: line 8: 26243 Terminated              sleep 60
  PID  PPID COMMAND
25048 25047 -bash
26242 25048  \_ /bin/bash /tmp/a1
26246 26242      \_ sleep 60
26247 26242      \_ /bin/ps Tfo pid ppid command
$-=hB
  PID  PPID COMMAND
25048 25047 -bash
26242 25048  \_ /bin/bash /tmp/a1
26248 26242      \_ /bin/ps Tfo pid ppid command


Is there another alternative to do this? "disown" would not work for
situation where "wait" is used to wait for child to finish  ...


sleep 80 &
P=$!
disown $P     # this would not work for 'wait' command next
(sleep 2; kill $P) &
wait $P


Thanks,
Jeff


reply via email to

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