Process API
fork
when call fork(), OS create a new process.
the two process is all same, and return from fork() function.
but according the man fork()
, when it create success.
- the child process receives a return code of 0
- the parent process receives the PID of the newly-created child process
wait
call wait() to delay its execution, until target proccess is completed
wait for any child process
wait(NULL) will block parent process until any of its children has finished
wait for all child process completed
POSIX defines a function: wait(NULL);. It's the shorthand for waitpid(-1, NULL, 0);
while ((wpid = wait(&status)) > 0);
exec
work with fork()
the exec family function will replace the current processs image with new process image.
so the rest codes of original process, will not execution.
execvp
The first argument, by convention, should point to the file name associated with the file being exe-cuted. The list of arguments must be terminated by a NULL pointer.
why
the separation of fork() and exec() is essential in building a UNIX shell
shell work flow
cmd: fork ------------------------ -> wait -> output
\ -> pre-env -> exec -> exit /
redirected
Specifically, UNIX systems start looking for free file descriptors at zero. In this case, STDOUT FILENO will be the first available one and thus get assigned when open() is called. Subsequent writes by the child process to the standard output file descriptor, for example by routines such as printf(), will then be routed transpar- ently to the newly-opened file instead of the screen.
extension
init
The process 1, and PID=1
the very first process (called init) is started by the kernel at booting time and never terminates
Zombie Process
A child that terminates, but has not been waited for becomes a "zombie".
Orphan Process
running process whose parent process has finished or terminated
Re-parenting
In most cases, the new parent is the
init
process, one with the PID 1.
Daemon Process
is an intintionally orphaned process
A daemon process is usually created by a process forking a child process and then immediately exiting, thus causing init to adopt the child process. In a Unix environment, the parent process of a daemon is often, but not always, the init process.
references
原文地址:https://www.cnblogs.com/Gilfoyle/p/15227380.html
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 分布式锁的封装也很有讲究呀
- PHP与SEO,应用curl及正则获取搜狗搜索相关关键词
- Kafka经典面试题,你都会吗?
- 提高单细胞分析准确度的工具之一:Self-assembling manifolds
- 一不小心肝出了4W字的Redis面试教程
- 双向LSTM-CRF模型用于序列标注
- 容器服务 TKE 上服务暴露的几种方式
- 【论文分享】ACL 2020 信息抽取任务中的新动向
- 工匠人iOS 代码规范
- 写一个通用的幂等组件,我觉得很有必要
- PC性能监测工具,您不可或缺的好帮手~~
- 特征工程之处理时间序列数据
- Matplotlib中的“plt”和“ax”到底是什么?
- 使用深度学习模型创作动漫故事,比较LSTM和GPT2的文本生成方法
- 聊聊BitCaskLock