C中要使用的其他一些不相关进程的进程ID [英] process id of some other unrelated process to be used in C

查看:105
本文介绍了C中要使用的其他一些不相关进程的进程ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C中是否可以使用函数或系统调用来查找其他进程的进程ID?

说,在进程A中,我想找到进程B的进程ID?是否有一些类似于getpid()的函数?

is there a function or system call in C which I can use to find Process ID of some other process?

Say, in process A I want to find the process ID of process B? Is there some function for this similar to getpid()?

推荐答案

我不知道这样的函数.但是您可以通过列出并解析proc文件系统中/proc/[pid] 条目中的信息来编写自己的信息(请参阅 ^ ]).

另一种解决方案是使用popen()函数执行 ps 命令,并为其他进程的名称解析输出.
I don''t know such function. But you may write your own by listing and parsing the information from the /proc/[pid] entries in the proc file system (see man 5 proc[^]).

Another solution would be execution of the ps command with the popen() function and parsing the output for the name of the other process.


这篇关于C中要使用的其他一些不相关进程的进程ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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