LINUX多进程编程 简单实例
1.ps与top命令 查看进程状态
2.系统调用ping,并执行
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
int main()
{
int main()
{
char *exec_argv[4];
exec_argv[0] = "ping";
exec_argv[1] = "127.0.0.1";
exec_argv[2] = NULL;
exec_argv[3] = NULL;
if (execv("/bin/ping", exec_argv) == -1)
{
printf("execv error!\n");
}
return 0;
}
3.用户程序调用
父进程包含子进程的创建,父子进程都包含死循环。
【Crtl+C】终止进程
#include<signal.h>
#include<unistd.h>
#include<sys/types.h>
#include <stdio.h>
#include <string.h>
#