Linuxc:创建与监控多个子进程
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
#include <signal.h>
#include <stdio.h> //子进程个数
#define SUB_PRO_COUNT 10 //处理子进程的退出信号
void sub_quit_signal_handle(int sig); //父进程的事件循环
void ParentCycle(); //子进程的事件循环
void ChildCycle(); int main(void)
{
pid_t pid;
int i; //创建SUB_PRO_COUNT个子进程
for(i=; i<SUB_PRO_COUNT; i++)
{
pid = fork();
if( == pid || - == pid )
break;
} //创建子进程失败
if( - == pid )
{
printf("No. %d: fork error\n", i);
}
//子进程的事件循环
else if( == pid )
{
ChildCycle();
}
//父进程的事件循环
else
{
ParentCycle();
} return ;
} void sub_quit_signal_handle(int sig)
{
int status;
//获取退出的那个子进程的状态
int quit_pid = wait(&status);
printf("sub process %d quit, exit status %d\n", quit_pid, status); //新创建一个子进程
pid_t pid = fork();
if( == pid )
ChildCycle();
} void ParentCycle()
{
printf("Parent process %d\n", getpid());
signal(SIGCHLD, sub_quit_signal_handle);
while()
pause();
} void ChildCycle()
{
printf("create sub process id: %d, parent id: %d\n", getpid(), getppid());
while()
pause();
}
Linuxc:创建与监控多个子进程的更多相关文章
- fork同一时候创建多个子进程的方法
Fork同一时候创建多个子进程方法 第一种方法:验证通过 特点:同一时候创建多个子进程.每一个子进程能够运行不同的任务,程序 可读性较好,便于分析,易扩展为多个子进程 int main(void) { ...
- Linux之创建多个子进程
/*** fork_test.c ***/ #include<stdio.h> #include<stdlib.h> #include<unistd.h> int ...
- Linux下性能监控、守护进程与计划任务管理
目录 一:监视系统进程(ps .top) 二:查看网络连接信息 (netstat) 三:文件进程.端口关联(lsof) 四:计划任务管理(at .crontab) at crontab 一:监视系统进 ...
- PHP多进程学习(二)__fork起多个子进程,父进程的阻塞与非阻塞
先简单来了解一下多进程 [来初步了解一下PHP多进程及简单demo] php的多进程是不是可以无限制的fork子进程?fork调用的一个奇妙之处就是它仅仅被调用一次,却能够返回两次,它可能有三种不同的 ...
- Linux 下监控用户最大进程数参数(nproc)是否到达上限
Linux 下监控用户最大进程数参数(nproc)是否到达上限的步骤: 1.查看各系统用户的进程(LWP)数: 注意:默认情况下采用 ps 命令并不能显示出所有的进程.因为 Linux 环境下执行多线 ...
- 创建属于其他Session的进程
创建其他Session(User)的进程需要拿到对应Session的Token作为CreateProcessAsUser的参数来启动进程. 修改有System权限的Token的TokenId为其他Se ...
- 用monit监控系统关键进程
原地址: https://feilong.me/2011/02/monitor-core-processes-with-monit monit是一款功能强大的系统状态.进程.文件.目录和设备的监控软件 ...
- 一个用pyton写的监控服务端进程的软件hcm
使用udp实现,简单,方便,不用三次握手 1. 所有部署服务器进程的机器有一个代理进程hagent,用来监听hcm console中发送过来的命令 2.hcm需要提供以下命令 start :普通方式启 ...
- 怎么查看一个进程里fork多少个子进程
怎么查看一个进程里fork多少个子进程 怎么查看一个进程里fork多少个子进程 怎么查看一个进程里fork多少个子进程 ? ? ?
随机推荐
- 观察者(Observer)模式
http://www.cnblogs.com/zhenyulu/articles/73723.html 一. 观察者(Observer)模式 观察者模式又叫做发布-订阅(Publish/Subscri ...
- [codeforces 360]A. Levko and Array Recovery
[codeforces 360]A. Levko and Array Recovery 试题描述 Levko loves array a1, a2, ... , an, consisting of i ...
- 联合主键用Hibernate注解映射的三种方式
第一.将联合主键的字段单独放在一个类中,该类需要实现java.io.Serializable接口并重写equals和hascode,再将该类注解为@Embeddable,最后在主类中(该类不包含联合主 ...
- MySQL分配角色权限
1.创建新用户 通过root用户登录之后创建 >> grant all privileges on *.* to testuser@localhost identified by &quo ...
- r-cnn学习(二)
faster r-cnn 1.问题 在fast r-cnn中,proposals已经成为速度提高的瓶颈.在本文中,使用深度网络来计算proposals, 使得与检测网络的计算量相比,proposals ...
- Ubuntu14.04安装intel集显驱动
Ubuntu14.04安装intel集显驱动 标签(空格分隔): ubuntu linux 驱动安装 1.查看本机显卡型号 使用lspci命令来获取PCI接口硬件信息 o@o-pc:~$ lspci ...
- 移动前端头部mete
原文链接:http://caibaojian.com/mobile-meta.html//code from http://caibaojian.com/mobile-meta.html<!DO ...
- rpm包制作(待实验)
作者:firefoxbug 时间:July 18, 2014 rpm包命名规范 对于rpm包的命名符合如下规范. %{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}.rpm N ...
- git config proxy
$ export http_proxy=http://proxy.ip.ad.ress:portnumber/ $ export https_proxy=http://proxy.ip.ad.ress ...
- Union-Find Algorithm
Union-Find Algrithm is used to check whether two components are connected or not. Examples: By using ...