From 4c4c880a75df4be245a07005cf9fa857a087aab3 Mon Sep 17 00:00:00 2001 From: onceupon Date: Thu, 23 Nov 2017 10:40:30 +0800 Subject: [PATCH] add other: wait wait for a pid (job) to complete --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 353ad4e..9ba8fd7 100644 --- a/README.md +++ b/README.md @@ -752,7 +752,7 @@ while read a b c; do echo $(($c-$b));done < <(head filename) i=0; while read a b c; do ((i+=$c-$b)); echo $i; done < <(head filename) ``` -##### While loop, keep checking a running process (e.g. perl) and start another new process (e.g. python) immetiately after it. +##### While loop, keep checking a running process (e.g. perl) and start another new process (e.g. python) immetiately after it. (BETTER use the wait command! Ctrl+F 'wait') ```bash while [[ $(pidof perl) ]];do echo f;sleep 10;done && python timetorunpython.py @@ -1634,6 +1634,14 @@ cat filename|rev|cut -f1|rev ##### pass password to ssh ```bash sshpass -p mypassword ssh root@10.102.14.88 "df -h" +``` + ##### wait for a pid (job) to complete +```bash +wait %1 +or +wait $PID +wait ${!} +#wait ${!} to wait till the last background process ($! is the PID of the last background process) ```