Subject: piping "ping" output in a background job
To: netbsd-help <netbsd-help@netbsd.org>
From: James K. Lowden <jklowden@schemamania.org>
List: netbsd-help
Date: 10/04/2003 16:50:47
$ ping -i 120 -o di |xmessage -file - &
[4] 1305
$ jobs -ls; ps -aux |egrep '^USER|130[45]'
[4]+ 1304 Stopped (tty output) ping -i 120 -o di
1305 | xmessage -file -
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
jklowden 1305 0.0 0.0 24 28 p0 T 4:04PM 0:00.01 xmessage
-file
root 1304 0.0 0.2 352 248 p0 T 4:04PM 0:00.01 ping -i
120 -o
The machine "di" is down; I started the above poll to tell me when it
comes back up. But why is the job stopped? I don't understand.
"stopped" AIUI means ping, above, can't write to the tty. I'm guessing it
has something to do with the fact that ping is set-uid root, and job
control doesn't have any way to write its output to my tty. Except I'd
expect ping's output to go to its stdout, which obviously is piped to
xmessage. And except that traceroute(8) is also set-uid and works fine.
So I think it's something special about ping.
I tried putting the commands in a subshell and backgrounding that. Same
effect.
I notice that when I try the same command line with a working machine (so
ping succeeds immediately), it still blocks:
$ ping -i 120 -o sandbox |grep . &
[5] 1349
$ fg %5
ping -i 120 -o sandbox | grep .
PING sandbox (192.168.1.12): 56 data bytes
64 bytes from 192.168.1.12: icmp_seq=0 ttl=128 time=1.006 ms
----sandbox PING Statistics----
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 1.006/1.006/1.006/0.000 ms
It's a puzzlement. Anyone care to unpuzzle me?
--jkl