5 ms·
my simple jobqueue, if I need one waitfor() { while pgrep $1 >/dev/null; do sleep 2; done && $* }
by xtf 6y ago
my simple jobqueue, if I need one
waitfor() {
while pgrep $1 >/dev/null; do sleep 2; done && $*
}
- unhammer 6y agoIf I may provide some feedback: Line 2: while pgrep $1 >/dev/null; do sleep 2; done && $* ^-- SC2086: Double quote to prevent globbing and word splitting. ^-- SC2048: Use "$@" (with quotes) to prevent whitespace problems. Also, how do you pick the right job to wait for if several programs match $1? (E.g. if it's a bash script, $1 will be "bash", which on my system matches lots of things.) Also, a 2s sleep will slow things down if you want to use it for a whole lot of jobs. Also, this won't run your second command if the first command you wait for has already exited! Also, shouldn't $* be `shift; "$@"` or do you only ever queue jobs of the same command?
- xtf 6y agoJust a simple one when needed. cp, downloader, etc. Nothing too complicated.