Re: Redirecting output from "kill" command?
From: Greg Porr (gporr@gscdump)
Date: 04/02/03
- Next message: Dr. Richard E. Hawkins: "Re: Last chance for a vi/emacs mug"
- Previous message: Rich Teer: "Re: Playstation 2, XBox, GameCube Incredible Prices!!"
- In reply to: Erik Max Francis: "Re: Redirecting output from "kill" command?"
- Next in thread: Bub: "Re: Redirecting output from "kill" command?"
- Reply: Bub: "Re: Redirecting output from "kill" command?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
From: gporr@gscdump (Greg Porr) Date: 2 Apr 2003 10:44:39 -0500
In article <3E8A274D.34D5461C@alcyone.com> Erik Max Francis <max@alcyone.com> writes:
>Bub wrote:
>>
>> Thanks Erik, but I've tried that (the basic " 2> /dev/null") and it
>> doesn't work either...
>
>I suspect you're doing something wrong. Are you sure you're using a
>Bourne-like shell?
>
>max@oxygen:~% kill 123123123
>kill: kill 123123123 failed: no such process
>max@oxygen:~% kill 123123123 2> /dev/null
>max@oxygen:~%
If it's the "Terminated" message which you're trying to redirect,
that's written to stderr by the parent shell whose child has been killed,
not by the kill command itself. You'd have to redirect the parent shell's
stdout, but then you'd lose stuff like prompts, as well as the shell's
displaying of any background process ids.
Take a look at the following:
gporr@gscdump: truss -f -wall -o truss.out /bin/sh
gporr@gscdump: sleep 100 &
25797
gporr@gscdump: /bin/kill 25797
25797 Terminated
gporr@gscdump: exit
We can see all the processes involved:
gporr@gscdump: grep exec truss.out
25165: execve("/bin/sh", 0x08047C30, 0x08047C38) argc = 1
25797: execve("/usr/bin/sleep", 0x0806A164, 0x0806A344) argc = 2
25799: execve("/bin/kill", 0x08069F9C, 0x08069FA8) argc = 3
25801: execve("/bin/sh", 0x08069FC8, 0x08069FD8) argc = 3
Pid 25165 is the parent shell, pid 25797 is the sleep process which we
end up killing, pid 25799 is /bin/kill (a shellscript), and pid 25801
is another /bin/sh process kicked off by /bin/kill. It's pid 25801 which
actually executes the kill() system call.
Here are the relevant lines from the truss output which show pid 25165
(the parent shell) writing the "Terminated" message
to file descriptor 2 (stderr) :
25165: write(2, 0x080673EC, 17) = 17
25165: 32 35 37 39 37 20 54 65 72 6D 69 6E 61 74 65 64 !25797 Terminated !
Note that if you used "kill" instead of "/bin/kill", that's a shell builtin,
so /bin/kill and the other /bin/sh process wouldn't be needed.
In that case, the parent shell (pid 25165) would end up making the kill()
system call, but 25165 still waits for 25797 and then displays
the "Terminated" message.
Hope that helps.
- Greg Porr, NCR Corporation
- Next message: Dr. Richard E. Hawkins: "Re: Last chance for a vi/emacs mug"
- Previous message: Rich Teer: "Re: Playstation 2, XBox, GameCube Incredible Prices!!"
- In reply to: Erik Max Francis: "Re: Redirecting output from "kill" command?"
- Next in thread: Bub: "Re: Redirecting output from "kill" command?"
- Reply: Bub: "Re: Redirecting output from "kill" command?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|