美文网首页
fork 子进程

fork 子进程

作者: michael_jia | 来源:发表于2022-08-09 11:38 被阅读0次

waitpid() IBM 系列文章精粹,W开头的系列宏定义函数

fork()

Some of the important points on fork() are as follows:
The parent will get the child process ID with non-zero value.
Zero Value is returned to the child.
If there will be any system or hardware errors while creating the child, -1 is returned to the fork().
With the unique process ID obtained by the child process, it does not match the ID of any existing process group.

pipe()

int pipe(int fds[2]);
Parameters :
fd[0] will be the fd(file descriptor) for the read end of pipe.
fd[1] will be the fd for the write end of pipe.
Returns : 0 on Success, -1 on error.
call fork after creating a pipe, then the parent and child can communicate via the pipe.

execvp()

What happens to our C program now?
This function will give the control of the current process (C program) to the command. So, the C program is instantly replaced with the actual command.
So, anything that comes after execvp() will NOT execute, since our program is taken over completely!
However, if the command fails for some reason, execvp() will return -1.
So, whenever you use execvp(), if you want to maintain your C program, you generally use fork() to first spawn a new process, and then use execvp() on that new process.
This is called the “fork-exec” model, and is the standard practice for running multiple processes using C.

zombie 僵尸进程 <defunct>

相关文章

  • 系统编程--进程函数

    一、fork() 拷贝父进程,子进程的fork不执行,返回0,执行fork之后的所有代码父进程的fork返回子进程...

  • Android系统启动

    所有的进程都是init进程的子进程或孙进程。是init进程fork出子进程 fork:fork函数UNIX及类UN...

  • 进程相关fork()/exec()/wait()

    fork() fork()将父进程复制一份子进程, 在子进程中从fork()调用处继续执行, 之后的代码在父子进程...

  • fork()系统调用

    fork() 函数简介 fork系统调用用于创建一个新进程,称为子进程,它与进行fork()调用的进程(父进程)并...

  • python多进程学习笔记

    fork方式创建进程 简单的fork 主进程fork时返回值大于0,子进程fork时返回值等于0 os.getpi...

  • Linux内核简述

    进程 创建 创建进程用fork()函数。fork()为子进程创建新的地址空间并且拷贝页表。子进程的虚拟地址空间...

  • 服务器的并发模式

    fork进程 IO复用 线程 多进程 主进程监听,在循环中接受连接请求,当连接建立后,fork一个子进程,在子进程...

  • Android Zygote进程和app进程fork过程分析2

    进程fork的一些知识 在分析app进程fork时,先来简单普及进程fork相关的一些知识,后面会用到fork子进...

  • linux应用程序进程操作(fork vfork)

    1fork ,fork的子进程和父进程同时运行,运行顺序不确定 2 vfork先运行子进程,再运行父进程 3 fo...

  • fork 子进程

    Fork, exec, wait and exit system call explained in Linux[...

网友评论

      本文标题:fork 子进程

      本文链接:https://www.haomeiwen.com/subject/hdfnwrtx.html