Shell-php End C Program Loop

Source: Internet
Author: User
Keywords c shell php
#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

  • 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.