在C中访问过程PCB [英] To access PCB of process in C

查看:52
本文介绍了在C中访问过程PCB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Linux上工作,我有点困惑我是否可以访问过程PCB?如果是,那么我们可以访问其中的哪些内容并将其打印到终端上?如果没有,为什么不呢?

I am working in Linux and i have a little bit confusion that whether i can access the PCB of process or not? if yes then what content of it we can access it and print them on to the terminal and if not then why not?

感谢您回答.....

thanks for answering .....

推荐答案

如果使用PCB,则表示过程控制块,是和否...

If by PCB, you mean the Process Control Block, yes and no...

,因为它位于内核地址空间中,不能由用户进程直接访问.内核从/proc 下的PCB提供一些信息-请参见 proc的手册页(5) 了解详情.此信息通常以纯文本格式提供,并且可以轻松显示-尝试例如:

No, because it's in the kernel address space and cannot be accessed directly by user processes. The kernel makes some information from the PCB available under /proc - see the manpage for proc(5) for details. This information is generally available in plain text form and can be easily displayed - try, for example:

cat /proc/self/status

,因为使用内核调试工具, struct task_struct (以及其他相关结构).这不是一件容易的事.您需要对内核源代码有很好的了解.基本思想是尝试在/proc/kcore /proc/kmem 中定位该结构.您将需要管理(根)权限,并对内核内存布局有很好的了解.仅应在内核调试或探索时执行此操作-请不要在生产代码中执行此操作,尤其是内部内核结构的布局在内核版本之间更改而没有警告的情况下!

Yes, because using kernel debugging facilities the struct task_struct (and other related structures) for a process can be accessed. This is not an easy task; you'll need a good understanding of the kernel source code. The basic idea will be to try to locate the structure in /proc/kcore or /proc/kmem. You will need administrative (root) rights and a very good understanding of the kernel memory layout. This should be done only for kernel debugging or exploration - please don't do this in production code, particularly as the layout of internal kernel structures changes without warning between kernel versions!

这篇关于在C中访问过程PCB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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