c++ getpid函数

If we are working on the processes, signals related programming using C language in Linux; we require process ids which can be created through the code by using some functions. Therefore, we need some of the functions, data types which are able to retrieve the process ids.

如果我们正在处理这些过程,则表明在Linux中使用C语言进行相关的编程。 我们需要可以使用某些功能通过代码创建的进程ID。 因此,我们需要一些能够检索进程ID的函数和数据类型。

First of all, I would recommend to read pid_t type in C

首先,我建议阅读C语言中的pid_t类型

在C中获取进程ID的函数 (Functions to get process ids in C)

There are two functions which are used to get the process ids, the functions are:

有两个函数用于获取进程ID,这些函数是:

  1. getpid()

    getpid()

  2. getppid()

    getppid()

1)C语言中的getpid()函数 (1) getpid() function in C)

When any process is created, it has a unique id which is called its process id. This function returns the process id of the calling function.

创建任何进程时,它都有一个唯一的ID,称为其进程ID。 该函数返回调用函数的进程ID。

Syntax:

句法:

    pid_t getpid();

2)C语言中的getppid()函数 (2) getppid() function in C)

This function returns the process id of the parent function.

该函数返回父函数的进程ID。

Syntax:

句法:

    pid_t getppid();

Note: pid_t is the type of process id, which is an unsigned integer type of data type.

注意: pid_t是进程ID的类型,它是数据类型的无符号整数类型。

C程序演示getpid()和getppid()的示例 (C program to demonstrate example of getpid() and getppid())

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main(void)
{//variable to store calling function's process id
pid_t process_id;
//variable to store parent function's process id
pid_t p_process_id;
//getpid() - will return process id of calling function
process_id = getpid();
//getppid() - will return process id of parent function
p_process_id = getppid();
//printing the process ids
printf("The process id: %d\n",process_id);
printf("The process id of parent function: %d\n",p_process_id);
return 0;
}

Output

输出量

    The process id: 31120The process id of parent function: 31119

Header files

头文件

  1. stdio.h - it is used for printf() function

    stdio.h-用于printf()函数

  2. sys/types.h - it is used for pid_t type, that is the data type of the variables which are using to store the process ids.

    sys / types.h-用于pid_t类型,即用于存储进程ID的变量的数据类型。

  3. unistd.h - it is used for getpid() and getppid() functions

    unistd.h-用于getpid()和getppid()函数

翻译自: https://www.includehelp.com/c/getpid-and-getppid-functions-in-c-linux.aspx

c++ getpid函数

c++ getpid函数_C Linux中的getpid()和getppid()函数相关推荐

  1. Linux中的fork()和clone()函数

    原文地址:https://blog.csdn.net/qq_42837885/article/details/101950162 fork函数 在linux中fork函数是非常重要的函数,它从已存在进 ...

  2. pandas使用replace函数替换dataframe中的值:replace函数对dataframe中的多个值进行替换、即一次性同时对多个值进行替换操作

    pandas使用replace函数替换dataframe中的值:replace函数对dataframe中的多个值进行替换.即一次性同时对多个值进行替换操作 目录

  3. pandas使用replace函数替换dataframe中的值:replace函数对dataframe中指定数据列的值进行替换、替换具体数据列的相关值

    pandas使用replace函数替换dataframe中的值:replace函数对dataframe中指定数据列的值进行替换.替换具体数据列的相关值 目录

  4. c语言常用数学函数大全查询,C语言数学函数 C语言中全部可用的数学函数有哪些?...

    导航:网站首页 > C语言数学函数 C语言中全部可用的数学函数有哪些? C语言数学函数 C语言中全部可用的数学函数有哪些? 相关问题: 匿名网友: /*--------------------- ...

  5. Linux中main和初启函数,main 中的 argv和argc 到底是个啥意思?

    原标题:main 中的 argv和argc 到底是个啥意思? 前言 一般我们平时写main函数的话,一般都是写不带参数的比较多,而且也习惯了这样写:其实标准的形式写法,main函数是带两个参数的,这两 ...

  6. python文件定位函数_C语言中文件定位函数总结

    C语言中文件定位函数主要是:fseek, ftell, fsetpos, fgetpos. 先来讲前两个函数,这是最基本的定位函数: fseek函数:能把文件指针移动到文件任何位置,其原型是:int ...

  7. linux之getcwd函数解析,Linux 中C语言getcwd()函数的用法

    Linux 中C语言getcwd()函数的用法 先来看该函数的声明: #include char *getcwd(char *buf,size_t size); 介绍: 参数说明:getcwd()会将 ...

  8. Unix/Linux中的read和write函数

    文件描述符 对于内核而言,所有打开的文件都通过文件描述符引用.文件描述符是一个非负整数.当打开一个现有文件或创建一个新文件时,内核向进程返回一个文件描述符.当读或写一个文件时,使用open或creat ...

  9. Linux中的可重入函数和不可重入函数

    可重入函数 可重入函数(即可以被中断的函数)可以被一个以上的任务调用,而不担心数据破坏.可重入函数在任何时候都可以被中断,而一段时间之后又可以恢复运行,而相应的数据不会破坏或者丢失. 可重入函数使用的 ...

最新文章

  1. KMeans中的K怎么选择?Elbow method怎么实施?
  2. 您的手机上未安装应用程序 android 点击快捷方式提示未安装程序的解决
  3. PL/SQL developer执行的sql文件编码
  4. 23种设计模式C++实现UML+源码汇总
  5. 简单的flash小动画成品_怎么制作flash动画?看这里怎么说。
  6. VHDL中的左移函数
  7. qt4.8 mysql 驱动_Qt-4.8.5配置mysql驱动
  8. php入门速成(2),PHP入门速成(1)
  9. CSS 盒模型与box-sizing
  10. [Java]jvm参数选项中文文档
  11. java 将bean转化为map,将javabean转化为map对象
  12. Redis基本数据类型、应用场景、操作指令
  13. c语言字符型计算器,C语言字符计算器
  14. 嵌入式linux系统移植的四大步骤_基于ARM的Linux系统移植的方法
  15. 黑莓桌面管理器更新到5.0.1.37版本
  16. 机器学习的13种算法和4种学习方法,推荐给大家
  17. 运营书籍:从零开始做
  18. 【2021/12/21】MySQL的json查询之json_keys、json_object、json_overlaps、json_pretty
  19. android标签云:LabelView
  20. 添加ubuntu开机引导

热门文章

  1. Canny算子与霍夫变换检测圆与直线
  2. java oracle big5_Oracle字符集子集与超级的对应关系
  3. 【经典算法】:二分查找
  4. 《一出好戏》讲述人性,使用Python抓取猫眼近10万条评论并分析,一起揭秘“这出好戏”到底如何?...
  5. 短视频点赞任务系统新版UI完美运营级别
  6. 希腊字母表LaTex公式整理
  7. 2022/9/12(cf·div4#817)https://codeforces.com/contest/1722
  8. 港股餐饮巨头年中业绩秀:海底捞、九毛九还能再造“爆款”?
  9. mysql quartz_springBoot+mysql整合quartz(拿来即用)
  10. MySQL 高频面试题,最常问!