I have a utility that has a nasty habit of going quiet and staying there, I already know how long into the process it does this so I am using timeout
to fight this, but sometimes it does it before that time. Is there a tool similar to timeout
that will kill the process if it stops directing output to stdout?
Bash – Kill a process if it goes quiet for a certain amount of time
bashlinuxshellstdouttimeout
Related Question
- Linux Process Monitoring – Getting Disk I/O Statistics for a Single Process
- Bash – timeout without killing process in bash
- Bash – There are stopped jobs (on bash exit)
- Bash – How to set Timeout for an ssh command and also get back the result of remote commands
- Shell – shell command or utility for caching process output
Best Answer
With
zsh
, you could do:The idea being to use the
-t
option ofsysread
to read fromyour-command
output with a timeout.Note that it makes
your-command
's output a pipe. It may be thatyour-command
starts buffering its output when it doesn't go to a terminal, in which case you may find that it doesn't output anything in a while, but only because of that buffering, not because it's hung somehow.You could work around that by using
stdbuf -oL your-command
to restore line-buffering (if your-command uses stdio) or usezpty
instead ofcoproc
to fake a terminal output.With
bash
, you'd have to rely ondd
and GNUtimeout
if available:Instead of
coproc
, you could also use process substitution:(that won't work in
zsh
orksh93
because$!
doesn't contain the pid ofyour-command
there).