The example of using php to guard another php process and to guard another php process. An example of using php to guard another php process. to guard another php process, use php to guard another php process (except for running the apache module and nginx). php needs to guard B. p: an example of using php to guard another php process.
Use php to guard another php process (except for running the apache module and nginx)
A. php should guard B. php
In B. php, use the getmypid () function to obtain the id of the current process and write the id to the c. pid file. if the program is executed, delete or clear the c. pid file.
In. verify c. whether the pid exists and is empty. if not, read the pid and execute ps-p pid | grep file name through exec to determine whether the pid is running. then, execute the corresponding operation.
Someone may ask why the ps aux | grep file name is not directly used. this is mainly because the file name is duplicated.
A. php code
The code is as follows:
<?
$ Id = intval ($ argv [1]);
If (! File_exists ('pid '. $ id.'. pid ')){
Echo "not run ";
Exit;
}
$ Content = file_get_contents ('pid '. $ id.'. pid ');
If (empty ($ content )){
Echo "not run ";
Exit;
}
Exec ("ps p". $ content. '| grep B. php', $ pids );
If (count ($ pids)> 0) echo ('runing ');
Else {echo 'not run ';}
?>
B. php code
The code is as follows:
<?
$ Id = intval ($ argv [1]);
If (empty ($ id) exit;
File_put_contents ('pid '. $ id.'. pid ', getmypid ());
While (1 ){
File_put_contents ('pid '. $ id.'. pid ', getmypid ());
Sleep (100 );
}
?>
Ghost should use php to guard another php process (except for running the apache module and nginx). a. php should guard B. p...