c进程学习日志
#include<unistd.h>
#include<sys/types.h>
#include<pwd.h>
#include<stdio.h>
int main(int argc,char **argv)
{
pid_t my_pid,parent_pid;
pid_t te ;
my_pid=getpid();
parent_pid=getppid();
printf("mypid is [%d]\t parentid is [%d]\n",my_pid,parent_pid);
te = fork();
printf("*********begin*************\n");
my_pid=getpid();
parent_pid=getppid();
printf("mypid is [%d]\t parentid is [%d]\t te is %d\n",my_pid,parent_pid,te);
printf("*********end*************\n");
#if 0
te = fork();
my_pid=getpid();
parent_pid=getppid();
printf("mypid is [%d]\t parentid is [%d]\t te is %d\n",my_pid,parent_pid,te);
getchar();
#endif
RESULT:
mypid is [1705] parentid is [1521]
*********begin*************
mypid is [1705] parentid is [1521] te is 1706
*********end*************
root@ubuntu:/usr/lsrcc/tempUserFun# *********begin*************
mypid is [1706] parentid is [1] te is 0
*********end*************
结果分析:调用fork一次,fork返回2次,一个是父进程,一个是子进程。
#include<unistd.h>
#include<sys/types.h>
#include<pwd.h>
#include<stdio.h>
int main(int argc,char **argv)
{
pid_t my_pid,parent_pid;
pid_t te ;
my_pid=getpid();
parent_pid=getppid();
printf("mypid is [%d]\t parentid is [%d]\n",my_pid,parent_pid);
te = fork();
printf("*********begin*************\n");
my_pid=getpid();
parent_pid=getppid();
printf("mypid is [%d]\t parentid is [%d]\t te is %d\n",my_pid,parent_pid,te);
printf("*********end*************\n");
#if 1 printf("*********2THbegin*************\n");
te = fork();
my_pid=getpid();
parent_pid=getppid();
printf("mypid is [%d]\t parentid is [%d]\t te is %d\n",my_pid,parent_pid,te); printf("********2TH*end*************\n");
getchar();
#endif }
RESULT:
*********begin*************
mypid is [1801] parentid is [1521] te is 1802
*********end*************//第一次fork父进程
*********2THbegin*************
mypid is [1801] parentid is [1521] te is 1803//第2次fork的父进程(在第一次fork的父进程基础上)
********2TH*end*************
mypid is [1803] parentid is [1801] te is 0//第2次fork的子进程(在第一次fork的父进程基础上)
********2TH*end*************
*********begin*************
mypid is [1802] parentid is [1801] te is 0
*********end*************//第1次fork的子进程
*********2THbegin*************
mypid is [1802] parentid is [1801] te is 1804//第2次fork的父进程(在第2次fork的父进程基础上)
********2TH*end*************
mypid is [1804] parentid is [1802] te is 0//第2次fork的子进程(在第2次fork的父进程基础上)
********2TH*end*************
系统运行结束后有6个进程。
#include<unistd.h>
#include<sys/types.h>
#include<pwd.h>
#include<stdio.h>
int main(int argc,char **argv)
{
pid_t my_pid,parent_pid;
pid_t te ;
static int count = ;
my_pid=getpid();
parent_pid = getppid();
int i = ;
const char *p = "/usr/lsrcc/dMF/main";
for(i = ;i < ;++i){
te = fork();
if(te < ){
printf("fork err!\n");
return -;
}
if(te > ){ printf("i is %i \nmypid is [%d]\t parentid is [%d]\t te is %d\n",i,my_pid,parent_pid,te);
printf("this is PARENT\n");
count++;
}
else if( == te){
printf("i is %i\nmypid is [%d]\t parentid is [%d]\t te is %d\n",i,my_pid,parent_pid,te);
printf("this is CHILD\n");
count++;
execlp(p,NULL);
} }
printf("count is %d\n",count); }
RESULT:
i is 0
mypid is [2798] parentid is [2361] te is 2799
this is PARENT
i is 1
mypid is [2798] parentid is [2361] te is 2800
this is PARENT
count is 2
root@ubuntu:/usr/lsrcc/tempUserFun# i is 1
i is 0
mypid is [2798] parentid is [2361] te is 0
this is CHILD
This is mytool1 print hello
mypid is [2798] parentid is [2361] te is 0
this is CHILD
This is mytool1 print hello
This is mytool2 print hello
This is mytool2 print hello
//主要提供一个子进程调用的例子
c进程学习日志的更多相关文章
- Cortex-M3学习日志(五) -- DAC实验
终于逮了个忙里偷闲的机会,就再学一下LPC1768的外围功能吧,循序渐进是学习的基本规则,也许LPC1768的DAC与8位单片机16位单片机里面集成的DAC操作类似,但是既然这是懒猫的学习日志,就顺便 ...
- Linux学习日志——基本指令②
文章目录 Linux学习日志--基本指令② 前言 touch cp (copy) mv (move) rm vim 输出重定向(> 或 >>) cat df(disk free) f ...
- GRE学习日志
发现开博客园真的很有督促作用,今天也顺便开个GRE学习日志吧 2015-02-09:单词 2015-02-10:单词 2015-02-11:单词 2015-03-02:阅读 2015-03-04:阅读 ...
- Cortex-M3学习日志(六) -- ADC实验
上一次简单的总结了一下DAC方面的知识,好吧,这次再来总结一下ADC方面的东东.ADC即Analog-to-Digital Converter的缩写,指模/数转换器或者模拟/数字转换器.现实世界是由模 ...
- webpack2学习日志
webpack说容易也容易,说难也难,主要还是看个人,想学到什么样的程度,很多公司可能要求仅仅是会用就行,但是也有一些公司要求比较高,要懂一些底层的原理,所以还是要花一些时间的,看个人需求.这篇仅仅是 ...
- javascript学习日志:前言
javascript学习日志系列的所有博客,主要理论依据是<javascript权威指南>(犀牛书第6版)以及<javascript高级程序设计第三版>(红色书),目前js行业 ...
- MobileForm控件的使用方式-用.NET(C#)开发APP的学习日志
今天继续Smobiler开发APP的学习日志,这次是做一个title.toolbar.侧边栏三种效果 样式一 一. Toolbar 1. 目标样式 我们要实现上图中的效果 ...
- 我的游戏学习日志3——三国志GBA
我的游戏学习日志3——三国志GBA 三国志GBA由日本光荣公司1991~1995所推出<三国志>系列游戏,该作是光荣在GBA上推出的<三国志>系列作品的第一款.本游戏登场武将总 ...
- 【转】Cocos2d-x 3.1.1 学习日志6--30分钟了解C++11新特性
[转]Cocos2d-x 3.1.1 学习日志6--30分钟了解C++11新特性 Cocos2d-x 3.1.1 学习日志6--30分钟了解C++11新特性
随机推荐
- CSS背景使用,引入、尺寸、平铺、定位、多重背景
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> ...
- Linux基础、常用命令
Linux作为IT程序员必知必会知识,将自己学习到的和最近工作常用的一些命令进行总结,作为我结束过去生活和开始类程序员的序吧! 如果你想系统性学习的话,还是建议看书(鸟哥的Linux私房菜)或网上视频 ...
- WoSign全球可信网站安全认证签章安装指南
您购买了WoSign SSL证书后,将免费获得一个能直观地显示贵网站的认证信息的可信网站安全认证标识,能大大增强用户的在线信任,促成更多在线交易.所以,建议您在安装成功SSL证书后马上在网站的首页和其 ...
- 将Oracle中的数据放入elasticsearch
package com.c4c.test; import java.sql.Connection; import java.sql.DriverManager; import java.sql.Res ...
- 关于@SuppressWarnings("unchecked")注解
解释一: 屏蔽某些编译时的警告信息 在强制类型转换的时候编译器会给出警告 加上程序代码 @SuppressWarnings("unchecked& ...
- java发送邮件带附件
package com.smtp; import java.util.Vector; public class MailBean { private String to; // 收件人 private ...
- SaltStack介绍——SaltStack是一种新的基础设施管理方法开发软件,简单易部署,可伸缩的足以管理成千上万的服务器,和足够快的速度控制,与他们交流
SaltStack介绍和架构解析 简介 SaltStack是一种新的基础设施管理方法开发软件,简单易部署,可伸缩的足以管理成千上万的服务器,和足够快的速度控制,与他们交流,以毫秒为单位.SaltSta ...
- POJ 3342 树形DP+Hash
这是很久很久以前做的一道题,可惜当时WA了一页以后放弃了. 今天我又重新捡了起来.(哈哈1A了) 题意: 没有上司的舞会+判重 思路: hash一下+树形DP 题目中给的人名hash到数字,再进行运算 ...
- chrome的全局搜索快捷键
常用 文件内搜索 ctrl+f 使用快捷键 ctrl+shift+f, 就会进入到全局搜索模式 打开文件:ctrl+o 打开DevTools 你可以通过以下任何一种方式来访问DevTools: 打开浏 ...
- C#调用webservice(二)
第二篇调用webservice,web服务是http://webservice.webxml.com.cn/webservices/DomesticAirline.asmx,航班查询服务 添加web服 ...