Create process in UNIX like system
In UNIX, as we’ve seen, each process is identified by its process identifier,
which is a unique integer. A new process is created by the fork() system call. The new process consists of a copy of the address space of the original process. This mechanism allows the parent process to communicate easily with its child process. Both processes (the parent and the child) continue execution at the instruction after the fork(), with one difference: the return code for the fork() is zero for the new (child) process, whereas the (nonzero) process identifier of the child is returned to the parent.
Typically, the exec() system call is used after a fork() system call by one of the two processes to replace the process’s memory space with a new program. The exec() system call loads a binary file into memory (destroying the memory image of the program containing the exec() system call) and starts its execution. In this manner, the two processes are able to communicate and then go their separate ways. The parent can then create more children; or, if it has nothing else to do while the child runs, it can issue a wait() system call to move itself off the ready queue until the termination of the child.
eg:
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
int main()
{
pid t pid;
/* fork a child process */
pid = fork();
if (pid < 0) { /* error occurred */
fprintf(stderr, "Fork Failed");
return 1;
}
else if (pid == 0) { /* child process */
execlp("/bin/ls","ls",NULL);
}
else { /* parent process */
/* parent will wait for the child to complete */
wait(NULL);
printf("Child Complete");
}
}
return 0;
Create process in UNIX like system的更多相关文章
- Global UNIX file system cylinder group cache
A global cylinder group (CG) cache is stored in file server memory and shared by a plurality of file ...
- pip/easy_install failure: failed to create process
使用pip install requests安装requests, 报错: failed to create process 解决方法: 执行Python -m pip install --upgra ...
- 运行easy_install安装python相关程序时提示failed to create process
运行easy_install安装python相关程序时提示failed to create process,因为安装了两个python,卸载了的那个目录没删除,删除了另外的python目录后这个问题就 ...
- Fatal error in launcher: Unable to create process using '"'
今天遇到了 Fatal error in launcher: Unable to create process using '"' 这个问题,原来是我上次装python3.5的时候,pyth ...
- delphi调试需要管理员权限程序报错“Unable to create process:请求的操作需要提升”
delphi调试启动需要UAC权限的程序的时候会报错“Unable to create process:请求的操作需要提升”.这是因为delphi没有以管理员身份启动,这样delphi createp ...
- Fatal error in launcher:Unable to create process using '"'
Windows下同时存在Python2和Python3使用pip时系统报错:Fatal error in launcher: Unable to create process using '" ...
- python3.6执行pip3时 Unable to create process using '"'
问题需求 由于在windows操作系统中已经安装了python2.7,要在安装python3的时候 将python3.6安装在C:\Python36目录下 然后进入C:\Python36目录下执行pi ...
- pip错误-failed to create process/fatal error in launcher
电脑同时装了python2和python3,并且都配置了环境变量 将python2的python.exe改成python2.exe,python3的python.exe没有改(主要用python2时则 ...
- pip ipython启动错误 Fatal error in launcher: Unable to create process using
完整的错误提示: C:\Users\yyy>ipython3Fatal error in launcher: Unable to create process using '"c:\u ...
随机推荐
- auth src
https://github.com/jbeverly/pam_ssh_agent_auth https://github.com/aur-archive/pam-face-authenticatio ...
- django 上传图片、使用PIL制作缩略图并保存到sea的storage
上传图片解析: SAE的设置指引如下: 处理用户上传文件 在setttings.py中添加以下配置. # 修改上传时文件在内存中可以存放的最大size为10m FILE_UPLOAD_MAX_MEMO ...
- python 结束练习
1.文件操作有哪些模式?请简述各模式的作用 r 只读模式 r+ 读写 rb w 只写模式 w+ 写读 wb x 只写模式 x+ 写读 xb a 追加模式 a+ 写读 ab 2.s = '**hello ...
- Java中的原子操作类
转载: <ava并发编程的艺术>第7章 当程序更新一个变量时,如果多线程同时更新这个变量,可能得到期望之外的值,比如变量i=1,A线程更新i+1,B线程也更新i+1,经过两个线程操作之后可 ...
- hdu 1325(并查集)
Is It A Tree? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- 微信小程序 - "锚点"功能的实现
“锚点”功能在实际应用设计的好,可以提高用户体验.今天碰到一个类似下面功能: 由于页面数据比较多,除了做些上拉加载,下拉刷新等优化.还可以进行进行分类,如上图.功能要求:点击导航的菜单,相应页面的分类 ...
- redis 安装及安装遇到的问题解决
https://blog.csdn.net/jy0902/article/details/19248299 http://q.fireflyclub.org/?/article/24 https:// ...
- java InputStream读取数据问题
原文 1. 关于InputStream.read() 在从数据流里读取数据时,为图简单,经常用InputStream.read()方法.这个方法是从流里每次只读取读取一个字节,效率会非常低. ...
- 走进 MvvmLight for Xamarin.Forms
一.Xamarin.Forms 不使用框架时的绑定 需要注意的是BindingContent,不是DataContent <ContentPage xmlns="http://xama ...
- Python基础系列----序列(列表、元组、字符串)
1.定义 1 ...