如果我有一个进程并克隆了它,那么PID是否相同? [英] If I have a process, and I clone it, is the PID the same?

查看:134
本文介绍了如果我有一个进程并克隆了它,那么PID是否相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个简单的问题,如果我克隆一个进程,那么所克隆的进程的PID是相同的,是吗? fork()创建一个子进程,其PID不同,但其他所有事物都相同. Vfork()创建具有相同PID的子进程. Exec致力于将当前正在执行的流程更改为其他流程.

Just a quick question, if I clone a process, the PID of the cloned process is the same, yes ? fork() creates a child process where the PID differs, but everything else is the same. Vfork() creates a child process with the same PID. Exec works to change a process currently in execution to something else.

我在所有这些陈述中都正确吗?

Am I correct in all of these statements ?

推荐答案

不太正确.如果通过fork/exec或vfork/exec克隆进程,则将获得新的进程ID. fork()将为您提供具有新进程ID的新进程,而exec()将用新进程替换该进程,但保留进程ID.

Not quite. If you clone a process via fork/exec, or vfork/exec, you will get a new process id. fork() will give you the new process with a new process id, and exec() replaces that process with a new process, but maintaining the process id.

此处:

vfork()函数与 fork()仅在子进程中 可以与 调用进程(父进程).这 显着加快克隆活动 冒着损害其完整性的风险 如果vfork()被滥用,则为父进程.

The vfork() function differs from fork() only in that the child process can share code and data with the calling process (parent process). This speeds cloning activity significantly at a risk to the integrity of the parent process if vfork() is misused.

这篇关于如果我有一个进程并克隆了它,那么PID是否相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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