《王保明老师----Linux开发学习笔记》------讲03:进程 -----fork( )函数 的疑问
来源:互联网 发布:js字符串中的双引号 编辑:程序博客网 时间:2024/05/25 21:33
#include<sys/types.h>
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<signal.h>
#include<errno.h>
#include<signal.h>
int main(void)
{
pid_t pid;
signal(SIGCHLD,SIG_IGN);
printf("before fork pid :%d \n",getpid());
int abc=0;
pid=fork(); // 子进程从此处开始执行。并且父进程会完成把堆栈段的复制到子进程中。
// 在此之前的代码完成的是父进程堆栈段、数据段的创建即给堆栈段赋值。
// 为什么子进程在此之后开始执行???
:
if(pid==-1)
{
printf("pid<0 err.\n");
return -1;
}
if(pid>0)
{
abc++;
printf("parent:pid %d \n",getpid());
sleep(11);
}
else if(pid==0)
{
abc++;
printf("child :%d ,parent:%d \n",getpid(),getpid());
printf("abc:%d \n",abc);
}
printf("for after ....\n");
return 0;
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<signal.h>
#include<errno.h>
#include<signal.h>
int main(void)
{
pid_t pid;
signal(SIGCHLD,SIG_IGN);
printf("before fork pid :%d \n",getpid());
int abc=0;
pid=fork(); // 子进程从此处开始执行。并且父进程会完成把堆栈段的复制到子进程中。
// 在此之前的代码完成的是父进程堆栈段、数据段的创建即给堆栈段赋值。
// 为什么子进程在此之后开始执行???
:
if(pid==-1)
{
printf("pid<0 err.\n");
return -1;
}
if(pid>0)
{
abc++;
printf("parent:pid %d \n",getpid());
sleep(11);
}
else if(pid==0)
{
abc++;
printf("child :%d ,parent:%d \n",getpid(),getpid());
printf("abc:%d \n",abc);
}
printf("for after ....\n");
return 0;
}
// 问题:??? 这个程序会打印出几个“hello world ”???
#include<unistd.h>
int main(void)
{
fork();
fork();
fork();
printf("hello world \n");
return 0;
}
// 问题:??? 这个程序会打印出几个“hello world ”???
我实验的是,打印了七次,但是为什么会打印七次呢????
0 0
- 《王保明老师----Linux开发学习笔记》------讲03:进程 -----fork( )函数 的疑问
- 《王保明老师----Linux开发学习笔记》------讲03:进程 -----fork( )函数 的疑问
- 《王保明老师----Linux开发学习笔记》------讲03:进程 -----fork( )函数的一点理解
- 《王保明老师----Linux开发学习笔记》------讲03:进程
- 《王保明老师----Linux开发学习笔记》------讲08:进程 -----多进程下的文件描述符
- 《王保明老师----Linux开发学习笔记》------讲09:进程 -----vfork()+execve()拉起一个可执行程序
- 《王保明老师----Linux开发学习笔记》------讲12:守护进程 -----如何分析和理解下面这个创建守护进程的实例
- Linux的进程学习笔记之fork与vfork
- Linux 进程学习1 --fork()函数
- 关于fork创建子进程的疑问
- Linux的进程函数fork的使用
- Linux创建进程的fork()函数
- Linux学习日记--fork()函数笔记
- linux 系统编程-学习笔记7-进程/fork/vfork/exec函数族
- Linux学习笔记-----文件系统的疑问????
- Linux基础学习系列:对于fork()函数的学习,及进程创建相关知识
- 【linux进程】fork函数浅析
- Linux进程创建fork()函数
- NYOJ 20 吝啬的国度 (DFS & vector)
- 【SQlite关系型数据库】SQLiteOpenHelper
- 计算机视觉、机器学习相关领域论文和源代码大集合--持续更新……
- 自定义导航控制器,统一设置Push的时候隐藏底部的tabbar
- iOS——个人公司型开发者账号申请流程(含免费邓白氏码申请流程)
- 《王保明老师----Linux开发学习笔记》------讲03:进程 -----fork( )函数 的疑问
- android 代码绘制转盘抽奖的实现
- Ubuntu安装ssh
- http://www.cnblogs.com/bluestorm/archive/2012/05/10/2493592.html
- 抽象类设计计算二维平面图形面积
- 二叉搜索树的后序遍历
- 简单的Python爬虫程序
- 对CMMI的认识
- Excel2016绘图新功能