linux进程fork函数的讲解。

通过指令,查看接口的详细信息

man fork

On success, the PID of the child process is returned in the parent, and 0 is returned in the child. On failure, -1 is returned in the parent, no child process is created, and errno is set appropriately.

这里的返回值的意思是,如果成功,孩子进程的pid会给父亲进程,然后0会给子进程。
如果失败,-1 的返回值给父亲,然后孩子进程不会被创建。
代码
在这里插入图片描述
makefile文件
在这里插入图片描述

结果,发现子进程的父节点为原始进程的pid。而父进程的父进程是什么呢 -》bash
在这里插入图片描述
这里不能说明什么,看下面的代码
在这里插入图片描述
结果,发现同一个pid有两个不同的值,这是多线程的基础,具体原理后面解释
在这里插入图片描述

相关推荐

最近更新

  1. TCP协议是安全的吗?

    2024-04-02 03:36:03       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-02 03:36:03       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-02 03:36:03       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-02 03:36:03       20 阅读

热门阅读

  1. 【代码随想录】【动态规划】day39:不同路径

    2024-04-02 03:36:03       16 阅读
  2. EMF相关学习文档

    2024-04-02 03:36:03       15 阅读
  3. web服务应用术语

    2024-04-02 03:36:03       17 阅读
  4. 阿里巴巴实习面经

    2024-04-02 03:36:03       21 阅读
  5. 竞赛常考的知识点大总结(二)基础算法

    2024-04-02 03:36:03       21 阅读
  6. vue3中computed详解

    2024-04-02 03:36:03       16 阅读
  7. vue——computed和methods的区别

    2024-04-02 03:36:03       15 阅读
  8. Vue 使用 array.flatMap()例子

    2024-04-02 03:36:03       15 阅读
  9. 远程过程调用-buttonrpc源码解析6-函数调用

    2024-04-02 03:36:03       16 阅读
  10. vue Props

    2024-04-02 03:36:03       15 阅读
  11. 【题解 | 01背包】分割等和子集

    2024-04-02 03:36:03       16 阅读