Linux 中创建进程
来源:互联网 发布:网络捕鱼游戏赢钱 编辑:程序博客网 时间:2024/05/09 12:48
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main(void)
{ int i;
int n = 4;
pid_t childpid;
for (i=1; i<n; i++)
{
if ((childpid = fork()) == 0) // 子进程 从fork()处开始执行
break;
if (childpid > 0)
sleep(1); //让父进程阻塞1秒
}
fprintf(stderr, "This is process %ld with parent %ld\n", (long)getpid(), (long)getppid());
return 0;
}
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
int main(int argc, char *argv[])
{ pid_t childpid;
int status;
if ((childpid = fork()) == -1)
{ //fork出错
perror("The fork failed");
exit(-1);
}
else if (childpid == 0)
{ //子进程
if (execl("./hello","hello",NULL) < 0)
{ //子进程执行另一个程序hello
perror("The exec of command failed");
exit(-1);
}
}
else if(childpid>0)
{ //父进程
pid_t apid = wait(&status); //父进程调用wait等待子进程
printf("parent process has wait the %ld child process exit\n",apid);
exit(0);
}
}
- Linux 中创建进程
- linux系统中进程的创建
- linux中fork创建进程讲解
- linux中fork创建进程讲解
- linux中fork创建进程讲解
- linux中fork创建进程讲解
- linux创建守护进程且进程中只有唯一实例
- Linux - 进程 (二) 进程创建
- linux 进程编程:进程创建
- [linux] 创建daemon进程
- Linux 进程创建
- Linux版进程创建
- linux 创建进程
- linux 管道创建进程
- Linux创建进程
- linux 创建进程
- linux 创建进程
- 20、Linux 进程创建
- USCAO 2.3.4
- USCAO 2.3.5
- POJ 1458
- POJ 1511
- USCAO 2.4.1
- Linux 中创建进程
- 【博文共赏】怎样花两年时间去面试一个人 转自刘未鹏的博客
- USCAO 2.4.2
- USCAO 2.4.3
- USCAO 2.4.4
- USCAO 2.4.5
- 知识产权管理系统优秀案例
- Eclipse导入Android工程出现Project has no default.properties file! Edit the project properties to set one.的解决方法
- Ubuntu 出现apt-get: Package has no installation candidate问题