日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

Linux Kernel Development——列出系统中所有的进程

發(fā)布時間:2025/3/19 linux 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Linux Kernel Development——列出系统中所有的进程 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

1. 在內(nèi)核模塊中列出所有的進程:

從init_task開始遍歷內(nèi)核鏈表,輸出所有進程

#include <linux/module.h> #include <linux/list.h> #include <linux/init.h> #include <linux/sched.h>MODULE_LICENSE("Dual BSD/GPL");static int test_init(void) {struct task_struct *task, *p;struct list_head *pos;int count=0;printk(KERN_ALERT "test module init\n");task=&init_task;list_for_each(pos, &task->tasks){p=list_entry(pos, struct task_struct, tasks);count++;printk(KERN_ALERT "%s[%d]\n", p->comm, p->pid);}printk(KERN_ALERT "Total %d tasks\n", count);return 0; }static void test_exit(void) {printk(KERN_ALERT "test module exit!\n"); }module_init(test_init); module_exit(test_exit);

Makefile

ifneq ($(KERNELRELEASE),)obj-m := test.o elseKDIR := /lib/modules/$(shell uname -r)/buildPWD := $(shell pwd)default:$(MAKE) -C $(KDIR) M=$(PWD) modules endif

2. 使用Systemtap輸出所有進程:

//process_list.stp%{ #include <linux/list.h> #include <linux/sched.h> %}function process_list () %{ struct task_struct *p;struct list_head *_p,*_n;for_each_process(p){_stp_printf("%-15s (%-5d)\n",p->comm,p->pid);} %}probe begin { process_list();exit() }

運行方法

# stap -g process_list.stp init (1 ) kthreadd (2 ) migration/0 (3 ) ksoftirqd/0 (4 ) migration/0 (5 ) watchdog/0 (6 ) migration/1 (7 ) migration/1 (8 ) ksoftirqd/1 (9 ) watchdog/1 (10 ) events/0 (11 ) events/1 (12 ) cpuset (13 ) khelper (14 ) netns (15 ) ....

3. 使用Systemtap打印進程uts命名空間信息

//namespace_uts.stp%{#include<linux/list.h>#include<linux/sched.h>#include <linux/nsproxy.h>#include<linux/utsname.h>%}function process_list ()%{struct task_struct *p;struct list_head *_p,*_n;struct uts_namespace *uts;struct new_utsname *utsname;for_each_process(p){uts=p->nsproxy->uts_ns;utsname=&(uts->name);_stp_printf("%-15s(%-5d) %-24s %-16s\n", p->comm,p->pid,utsname->release, utsname->sysname);}%}probe begin{process_list();exit()} # stap -g namespace_uts.stp init (1 ) 2.6.32-220.el6.x86_64 Linux kthreadd (2 ) 2.6.32-220.el6.x86_64 Linux migration/0 (3 ) 2.6.32-220.el6.x86_64 Linux ksoftirqd/0 (4 ) 2.6.32-220.el6.x86_64 Linux migration/0 (5 ) 2.6.32-220.el6.x86_64 Linux watchdog/0 (6 ) 2.6.32-220.el6.x86_64 Linux migration/1 (7 ) 2.6.32-220.el6.x86_64 Linux migration/1 (8 ) 2.6.32-220.el6.x86_64 Linux ....


本文轉(zhuǎn)自feisky博客園博客,原文鏈接:http://www.cnblogs.com/feisky/archive/2013/03/04/2943517.html,如需轉(zhuǎn)載請自行聯(lián)系原作者

總結(jié)

以上是生活随笔為你收集整理的Linux Kernel Development——列出系统中所有的进程的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。