关于fork和execve系统调用 [英] about fork and execve system call

查看:63
本文介绍了关于fork和execve系统调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据说, fork 系统调用创建了调用进程的克隆,然后(通常)子进程发出 execve 系统调用以更改其映像并运行一个新的过程.为什么要分两步走?

It is said that fork system call creates a clone of the calling process, and then (usually) the child process issues execve system call to change its image and running a new process. Why this two-step?

顺便说一句, execve 代表什么?

BTW, what does execve stand for?

推荐答案

每个步骤都相对简单.

在Unix中,您的过程分为两部分-带有应用程序代码的只读存储区(文本")和可读写存储区(数据").

In Unix, your process has two parts -- a read-only memory area with the application code ("text") and the read-write memory area ("data").

叉子将克隆读写区域,而将文本页面保留下来.现在,您有两个运行相同代码的进程.它们的区别在于寄存器值(fork的返回值),该值将父代与子代分开.

A fork clones the read-write area, leaving the text page alone. You now have two processes running the same code. They differ by a register value -- the return value from fork -- which separates parent from child.

执行程序替换文本页面,而将数据页面保留下来.exec有多种形式,具体取决于您要传递给它的环境信息的数量.有关其他内容,请参见 http://linux.die.net/man/3/exec 变体列表.

An exec replaces the text page, leaving the data page alone. There are many forms of exec, depending on how much environment information you're passing to it. See http://linux.die.net/man/3/exec for an additional list of variants.

这篇关于关于fork和execve系统调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆