timeout - Bash script that kills a output redirection after a period of time -


i'm looking lightweight solution kill command output redirection if hangs. current solution

if [[ -w /tmp/mypipe ]];   timeout --kill-after 10 5 echo "1" > /tmp/mypipe fi 

works if left part of command not work correctly (e.g. no 1 read pipe). discovered situation, redirection hangs -- @ least issue of not synchronized tasks, can't solve now.

there several related questions this, this or that. last 1 covers question, i'm still looking more slim solution. suggests work like

( cmdpid=$bashpid; \   (sleep 5; kill -9 $cmdpid >& /dev/null) & echo "1" > /tmp/mypipe ) 

but spawns 2 new bash processes. there more lightweight solution problem?

keep in mind each spawned bash process share vast majority of memory parent process, it's not tripling memory usage top have believe.

if still want try optimize, timeout 5 tee /tmp/mypipe <<< "1" > /dev/null spawn timeout , tee process instead.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -