#include
#include
#include
int loop;void Stoploop(void){ loop=0;}int main(int argc, char *argsv[]){int i;loop=1;while(loop==1){ printf("%d/n",i); i++;}return 0;}
For example, start running this program under Linux.
PHP side Call Shell_exec (); After executing the program, how to terminate the program loop?
Reply content:
#include
#include
#include
int loop;void Stoploop(void){ loop=0;}int main(int argc, char *argsv[]){int i;loop=1;while(loop==1){ printf("%d/n",i); i++;}return 0;}
For example, start running this program under Linux.
PHP side Call Shell_exec (); After executing the program, how to terminate the program loop?
In general, it should be compiled into a dynamic library so by the script call, and such an infinite loop should be the thread, and then need to stop the time to kill the threads directly.
Your C program is a permanent process AH. To terminate, is to kill the C program. Direct KILL command. Or you have this C program registered signal, you can send a signal to terminate.
Essentially you are PHP and C interprocess communication.
You can check out the IPC-related technical documentation for interprocess communication.
When the loop!=1 is over, the loop is over.
In a relatively simple and rude way, the same call Shell_exec (), "Kill-9 $pid" to terminate the program
C code change, loop=1; Change to the form of a variable