您的位置:首页 > 运维架构 > Linux

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

2017-10-12 20:17 525 查看
#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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: