Linux下一个进程重启自己的简单实现

#include 
  
  
   
   
#include 
   
   
    
    
#include 
    
    
     
     
#include 
     
     
      
      
#include 
      
      
        int main(int argc, char* argv[]) { int fd = open("tmp.txt", O_CREAT | O_APPEND | O_RDWR, 0666); char buf[] = "hello huang jia jia\n"; write(fd, buf, sizeof(buf)); close(fd); sleep(8); if(fork() == 0) { if(execl("a.out", NULL) < 0) { perror("Execl:"); } } return 0; } 
      
     
     
    
    
   
   
  
  


关闭进程命令:ps l | grep out | grep -v grep | cut -d' ' -f6 | xargs kill -9

你可能感兴趣的:(C/C++,Linux环境编程,linux)