note 22674 deleted from ref.exec by goba

From: Date: Wed, 02 Oct 2002 11:57:12 +0000
Subject: note 22674 deleted from ref.exec by goba
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-37540@lists.php.net to get a copy of this message
I needed to know when a group of background tasks, which had been launched with a call to system, had terminated. I could not find a function to call, so I created a little function. It basically loops on the existance of a string in the results returned by the command ps. All my commands, which run in background have the pid returned by posix_getpid in them. I am able to launch many background task and effectively wait for them all to finish. Before this, I would basically would sleep for N seconds. I apologise if a well known or better method exist. Thanks, The New Bee =============== =============== function wait_until_termination ($id, $duration){ $i = 0; do { $i += 1; $cnt = `ps -auxww | grep $id | grep -v grep | awk '{print $2}' | grep -v $id| wc -l` ; if ($cnt > 0) { sleep ($duration); } } while ($cnt != 0); echo ("wait_until_termination (PID: $id, SEC: $duration) : LOOPS :$i<BR>"); }

« previous php.notes (#37540) next »