I am running a process in a sub-shell which may or may not hang, then killing that process if it is still running after 10 seconds.
In doing so, I pipe stdout
and stderr
to /dev/null with > /dev/null 2>&1
, which seems to work. However, the output of the kill command then prints to stdout
after my next command, no matter what command I use.
[me@test] (Command_That_May_Hang.sh)&
[me@test] X=$!
[me@test] (sleep 10 && kill -9 $! > /dev/null 2>&1)&
[me@test] ps
> PID TTY TIME CMD
> 22741 pts/1 00:00:00 bash
> 27585 pts/1 00:00:00 ps
> [1]+ Killed Command_That_May_Hang.sh > /dev/null 2>&1
I have tried moving /dev/null 2>&1
to the outside of ()
and even after &
, with no change in results. For reference, those iterations look like:
(sleep 10 && kill -9 $!) > /dev/null 2>&1 &
(sleep 10 && kill -9 $!)& > /dev/null 2>&1
Executing the process and then killing it both work successfully, it just seems that I can only temporarily suppress the output, which is strange behavior. Any help on correctly sending output to /dev/null
would be appreciated.