如何在程序里面得到当前程序的进程 ID 号?

NewCenturyNewPage 2004-09-21 01:59:24
RT
...全文
195 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
noble01 2004-09-21
  • 打赏
  • 举报
回复
getpid,得到进程的id,getppid,得到父进程的id
lysliberty 2004-09-21
  • 打赏
  • 举报
回复
pid_t 不是结构,
是 unisigned int类型的数据。
getpid()就可以。
NewCenturyNewPage 2004-09-21
  • 打赏
  • 举报
回复
pid_t 的数据结构是怎么样的?
NewCenturyNewPage 2004-09-21
  • 打赏
  • 举报
回复
就好像一个kill 进程的命令,后面跟着的不是一个进程号吗?(这个号码是一个长整型的)

我想知道这个号码是多少,pid_t 怎么和它之间相互转化?
yanghuajia 2004-09-21
  • 打赏
  • 举报
回复
?
pid_t 根据系统可以不同。
NewCenturyNewPage 2004-09-21
  • 打赏
  • 举报
回复
这样得到的进程ID号是 pid_t 数据结构类型的,

我们通常见到的进程ID 号是一个长整型的数值,怎么转换?

Linux下如何用命令方式查看当前已有的进程的信息?
onlyf 2004-09-21
  • 打赏
  • 举报
回复
NAME
getpid, getppid - get process identification

SYNOPSIS
#include <sys/types.h>
#include <unistd.h>

pid_t getpid(void);
pid_t getppid(void);

DESCRIPTION
getpid returns the process ID of the current process. (This is often used by routines that generate
unique temporary file names.)

getppid returns the process ID of the parent of the current process.

CONFORMING TO
POSIX, BSD 4.3, SVID

SEE ALSO
exec(3), fork(2), kill(2), mkstemp(3), tmpnam(3), tempnam(3), tmpfile(3)

23,121

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧