Shell-PHP ends the C program Loop

Source: Internet
Author: User
{Code...}: for example, run this program in linux. The PHP side calls shell_exec (); after the program is executed, how does one terminate the program loop?
#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, run this program in linux.
The PHP side calls shell_exec (); after the program is executed, how does one 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, run this program in linux.
The PHP side calls shell_exec (); after the program is executed, how does one terminate the program loop?

Generally, it should be compiled into a dynamic library so called by the script, and such an infinite loop should open the thread, and then directly kill the thread when it needs to be stopped.

Your C program is a resident process. To terminate a program, you must kill the program C. Directly call the kill command. Or you have registered a signal in this C program, and you can send a signal to terminate it.

Essentially, you are the communication between PHP and C processes.
You can refer to the technical documents related to the inter-process communication IPC.

When loop! = 1. The loop ends.

In a simple and crude way, call shell_exec () and "kill-9 $ pid" to terminate the program.

Change the C code to loop = 1. Change it to the variable form.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.