/dev/null >&- <&- >/dev/null &'; exec( $command ); $ps_array = preg_split( "/\s+/", exec( $ps_command ) ); while ( !$pid ) { sleep( 1 ); $ps_array = preg_split( "/\s+/", exec( $ps_command ) ); $pid = $ps_array[3]; } } function stopDaemon( $daemon, $did ) { $ps_command = "ps -edalf | grep '$daemon $did' | grep -v grep"; $ps_array = preg_split( "/\s+/", exec( $ps_command ) ); if ( $ps_array[3] ) { $pid = $ps_array[3]; exec( "kill -TERM $pid" ); } else { return; } while( $pid ) { sleep( 1 ); $ps_array = preg_split( "/\s+/", exec( $ps_command ) ); $pid = $ps_array[3]; } } function controlDaemons( $device ) { $sql = "select count(if(Function='Passive',1,NULL)) as PassiveCount, count(if(Function='Active',1,NULL)) as ActiveCount from Monitors where Device = '$device'"; $result = mysql_query( $sql ); if ( !$result ) echo mysql_error(); $row = mysql_fetch_assoc( $result ); $passive_count = $row[PassiveCount]; $active_count = $row[ActiveCount]; if ( !$passive_count && !$active_count ) { stopDaemon( "zmc", $device ); } else { startDaemon( "zmc", $device ); } if ( !$active_count ) { stopDaemon( "zma", $device ); } else { startDaemon( "zma", $device ); } } ?>