如何用C遍历unixlinux下的所有进程,取得PID,名称等等

如何用C遍历unixlinux下的所有进程,取得PID,名称等等,第1张

用管道:

通过fgets(buf, n, ptr)buf就可以得到命令“ps -ef"一样的信息,

读帮助”man popen":

char *cmd = "ps -ef"

FILE *ptr

if ((ptr = popen(cmd, "r")) != NULL)

while (fgets(buf, n, ptr) != NULL)

(void) printf("%s ",buf)

UID PID PPID CSTIME TTYTIME CMD

root 0 0 0 Sep-30 ?00:00:01 sched

root 1 0 0 Sep-30 ?00:00:06 /etc/init -a

root 2 0 0 Sep-30 ?00:00:00 vhand

root 3 0 0 Sep-30 ?00:00:27 bdflush

root 4 0 0 Sep-30 ?00:00:00 kmdaemon

root 5 1 0 Sep-30 ?00:00:50 htepi_daemon /

root 6 0 0 Sep-30 ?00:00:00 strd

root 2941 1 0 Oct-08 tty0100:00:00 /bin/login ccb

root43 1 0 Oct-08 ?00:00:02 /etc/syslogd

root47 1 0 Oct-08 ?00:00:00 /etc/ifor_pmd

root4847 0 Oct-08 ?00:00:13 /etc/ifor_pmd

root36 1 0 Oct-08 ?00:00:00

layout: post

title: 如何遍历Linux程序的So模块

categories: Android

description: 如何遍历linux程序的so模块

keywords:

url: https://lichao890427.github.io/https://github.com/lichao890427/

  soinfo是个链表结构,从打印的信息来看,是从高地址到低地址排序的,因此要打开一个未加载的so,自然排在高地址位置,因此往后遍历即可


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/5931426.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-08
下一篇 2023-03-08

发表评论

登录后才能评论

评论列表(0条)

保存