- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在研究 Linux 内核模块。它需要有一种方法可以将所有进程显示为分层树。我已经编写了一个递归方法来显示进程及其子进程。我还尝试通过检查每个进程与 init_task
的距离来将其格式化为树。但是,我认为这棵树不正确。有人可以提示使用我编写的方法显示分层流程树的更好方法吗?非常感谢!
void print_tree(struct task_struct *root){
struct list_head *theList;
struct task_struct *new;
struct task_struct *new_copy;
char separator[100] = " ";
list_for_each(theList, &root->children){
new = list_entry(theList, struct task_struct, sibling);
new_copy = new;
while(new_copy->parent != &init_task){
new_copy = new_copy->parent;
strcat(separator, " ");
}
printk("%s ->[%d] %s\n",separator, new->pid, new->comm);
if((&new->children)->next != &new->children)
print_tree(new);
}
}
我得到的树:
[20291.173735] ->[1] systemd
[20291.173741] ->[121] systemd-journal
[20291.173745] ->[137] systemd-udevd
[20291.173749] ->[14456] systemd-udevd
[20291.173753] ->[155] dbus-daemon
[20291.173756] ->[160] systemd-logind
[20291.173760] ->[165] login
[20291.173764] ->[1872] bash
[20291.173768] ->[1947] xinit
[20291.173771] ->[1948] Xorg.bin
[20291.173776] ->[1951] sh
[20291.173780] ->[1956] xfce4-session
[20291.173784] ->[1974] xfwm4
[20291.173789] ->[1976] Thunar
[20291.173793] ->[1978] xfce4-panel
[20291.173798] ->[1992] panel-6-systray
[20291.173803] ->[1994] panel-2-actions
[20291.173807] ->[1980] xfdesktop
[20291.173812] ->[1983] xfce4-terminal
[20291.173816] ->[2006] gnome-pty-helpe
[20291.173821] ->[2010] bash
[20291.173825] ->[14454] sudo
[20291.173829] ->[14455] insmod
[20291.173833] ->[1852] systemd
[20291.173837] ->[1857] (sd-pam)
[20291.173840] ->[1898] dhcpcd
[20291.173844] ->[1960] dbus-daemon
[20291.173847] ->[1959] dbus-launch
[20291.173851] ->[1962] polkitd
[20291.173855] ->[1970] xfconfd
[20291.173858] ->[1973] gpg-agent
[20291.173862] ->[1981] xfsettingsd
[20291.173899] ->[1987] xfce4-power-man
[20291.173902] ->[1997] firefox
[20291.173906] ->[2004] upowerd
[20291.173910] ->[2036] at-spi-bus-laun
[20291.173914] ->[2075] gvim
[20291.173917] ->[6212] gvim
[20291.173921] ->[2] kthreadd
[20543.924720] ->[3] ksoftirqd/0
[20543.924720] ->[5] kworker/0:0H
[20543.924720] ->[6] kworker/u2:0
[20543.924720] ->[7] rcu_preempt
[20543.924720] ->[8] rcu_sched
[20543.924720] ->[9] rcu_bh
[20543.924720] ->[10] migration/0
[20543.924720] ->[11] watchdog/0
[20543.924720] ->[12] khelper
[20543.924720] ->[13] kdevtmpfs
[20543.928133] ->[14] netns
[20543.928142] ->[15] perf
[20543.928146] ->[16] khungtaskd
[20543.928150] ->[17] writeback
[20543.928154] ->[18] ksmd
[20543.928157] ->[19] khugepaged
[20543.928161] ->[20] crypto
[20543.928165] ->[21] kintegrityd
[20543.928169] ->[22] bioset
[20543.928172] ->[23] kblockd
[20543.928176] ->[24] devfreq_wq
[20543.928180] ->[26] kswapd0
[20543.928183] ->[27] fsnotify_mark
[20543.928188] ->[32] kthrotld
[20543.928191] ->[33] ipv6_addrconf
[20543.928195] ->[34] deferwq
[20543.928198] ->[58] ata_sff
[20543.928202] ->[59] scsi_eh_0
[20543.928206] ->[60] scsi_tmf_0
[20543.928210] ->[61] kworker/u2:2
[20543.928213] ->[62] scsi_eh_1
[20543.928217] ->[63] scsi_tmf_1
[20543.928221] ->[64] scsi_eh_2
[20543.928225] ->[65] scsi_tmf_2
[20543.928229] ->[73] kworker/0:1H
[20543.928232] ->[82] jbd2/sda1-8
[20543.928236] ->[83] ext4-rsv-conver
[20543.928240] ->[161] kpsmoused
[20543.928244] ->[1892] cfg80211
[20543.928248] ->[12406]kworker/0:0
[20543.928252] ->[13669] kworker/0:1
[20543.928256] ->[14017] kworker/0:2
[20543.928260] ->[14345] kworker/0:
这就是我打印所有当前进程及其父进程时得到的结果:
[15558.128445] Loading Module
[15558.128457] [1] systemd whose parent is swapper/0
[15558.128461] [2] kthreadd whose parent is swapper/0
[15558.128465] [3] ksoftirqd/0 whose parent is kthreadd
[15558.128482] [5] kworker/0:0H whose parent is kthreadd
[15558.129625] [6] kworker/u2:0 whose parent is kthreadd
[15558.129629] [7] rcu_preempt whose parent is kthreadd
[15558.129633] [8] rcu_sched whose parent is kthreadd
[15558.129637] [9] rcu_bh whose parent is kthreadd
[15558.129641] [10] migration/0 whose parent is kthreadd
[15558.129645] [11] watchdog/0 whose parent is kthreadd
[15558.129649] [12] khelper whose parent is kthreadd
[15558.129652] [13] kdevtmpfs whose parent is kthreadd
[15558.129656] [14] netns whose parent is kthreadd
[15558.129660] [15] perf whose parent is kthreadd
[15558.129663] [16] khungtaskd whose parent is kthreadd
[15558.129668] [17] writeback whose parent is kthreadd
[15558.129671] [18] ksmd whose parent is kthreadd
[15558.129675] [19] khugepaged whose parent is kthreadd
[15558.129678] [20] crypto whose parent is kthreadd
[15558.129682] [21] kintegrityd whose parent is kthreadd
[15558.129686] [22] bioset whose parent is kthreadd
[15558.129689] [23] kblockd whose parent is kthreadd
[15558.129693] [24] devfreq_wq whose parent is kthreadd
[15558.129696] [26] kswapd0 whose parent is kthreadd
[15558.129700] [27] fsnotify_mark whose parent is kthreadd
[15558.129704] [32] kthrotld whose parent is kthreadd
[15558.129708] [33] ipv6_addrconf whose parent is kthreadd
[15558.129711] [34] deferwq whose parent is kthreadd
[15558.129715] [58] ata_sff whose parent is kthreadd
[15558.129718] [59] scsi_eh_0 whose parent is kthreadd
[15558.129722] [60] scsi_tmf_0 whose parent is kthreadd
[15558.129726] [61] kworker/u2:2 whose parent is kthreadd
[15558.129729] [62] scsi_eh_1 whose parent is kthreadd
[15558.129733] [63] scsi_tmf_1 whose parent is kthreadd
[15558.129736] [64] scsi_eh_2 whose parent is kthreadd
[15558.129740] [65] scsi_tmf_2 whose parent is kthreadd
[15558.129744] [73] kworker/0:1H whose parent is kthreadd
[15558.129747] [82] jbd2/sda1-8 whose parent is kthreadd
[15558.129751] [83] ext4-rsv-conver whose parent is kthreadd
[15558.129755] [121] systemd-journal whose parent is systemd
[15558.129759] [137] systemd-udevd whose parent is systemd
[15558.129763] [155] dbus-daemon whose parent is systemd
[15558.129767] [160] systemd-logind whose parent is systemd
[15558.129771] [161] kpsmoused whose parent is kthreadd
[15558.129774] [165] login whose parent is systemd
[15558.129778] [1852] systemd whose parent is systemd
[15558.129782] [1857] (sd-pam) whose parent is systemd
[15558.129785] [1872] bash whose parent is login
[15558.129789] [1892] cfg80211 whose parent is kthreadd
[15558.129793] [1898] dhcpcd whose parent is systemd
[15558.129796] [1947] xinit whose parent is bash
[15558.129800] [1948] Xorg.bin whose parent is xinit
[15558.129803] [1951] sh whose parent is xinit
[15558.129807] [1956] xfce4-session whose parent is sh
[15558.129811] [1959] dbus-launch whose parent is systemd
[15558.129814] [1960] dbus-daemon whose parent is systemd
[15558.129818] [1962] polkitd whose parent is systemd
[15558.129822] [1970] xfconfd whose parent is systemd
[15558.129825] [1973] gpg-agent whose parent is systemd
[15558.129829] [1974] xfwm4 whose parent is xfce4-session
[15558.129832] [1976] Thunar whose parent is xfce4-session
[15558.129836] [1978] xfce4-panel whose parent is xfce4-session
[15558.129840] [1980] xfdesktop whose parent is xfce4-session
[15558.129844] [1981] xfsettingsd whose parent is systemd
[15558.129848] [1983] xfce4-terminal whose parent is xfce4-session
[15558.129851] [1987] xfce4-power-man whose parent is systemd
[15558.129855] [1992] panel-6-systray whose parent is xfce4-panel
[15558.129859] [1994] panel-2-actions whose parent is xfce4-panel
[15558.129862] [1997] firefox whose parent is systemd
[15558.129866] [2004] upowerd whose parent is systemd
[15558.129870] [2006] gnome-pty-helpe whose parent is xfce4-terminal
[15558.129874] [2010] bash whose parent is xfce4-terminal
[15558.129877] [2036] at-spi-bus-laun whose parent is systemd
[15558.129881] [2075] gvim whose parent is systemd
[15558.129885] [6212] gvim whose parent is systemd
[15558.129888] [6703] kworker/0:2 whose parent is kthreadd
[15558.129892] [9072] kworker/0:0 whose parent is kthreadd
[15558.129896] [9245] kworker/0:1 whose parent is kthreadd
[15558.129899] [9252] kworker/0:3 whose parent is kthreadd
[15558.129903] [10267] sudo whose parent is bash
[15558.129906] [10268] insmod whose parent is sudo
[15558.129910] [10269] systemd-udevd whose parent is systemd-udevd
最佳答案
当然,我没有刷新 separator
缓冲区是一个愚蠢的事实。通过简单地将其声明移动到 list_for_each
循环中来修复它。这棵树现在显示得很漂亮。
关于linux - arch linux内核显示进程树的写法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28484891/
关于 B 树与 B+ 树,网上有一个比较经典的问题:为什么 MongoDb 使用 B 树,而 MySQL 索引使用 B+ 树? 但实际上 MongoDb 真的用的是 B 树吗?
如何将 R* Tree 实现为持久(基于磁盘)树?保存 R* 树索引或保存叶值的文件的体系结构是什么? 注意:此外,如何在这种持久性 R* 树中执行插入、更新和删除操作? 注意事项二:我已经实现了一个
目前,我正在努力用 Java 表示我用 SML 编写的 AST 树,这样我就可以随时用 Java 遍历它。 我想知道是否应该在 Java 中创建一个 Node 类,其中包含我想要表示的数据,以及一个数
我之前用过这个库http://www.cs.umd.edu/~mount/ANN/ .但是,它们不提供范围查询实现。我猜是否有一个 C++ 范围查询实现(圆形或矩形),用于查询二维数据。 谢谢。 最佳
在进一步分析为什么MySQL数据库索引选择使用B+树之前,我相信很多小伙伴对数据结构中的树还是有些许模糊的,因此我们由浅入深一步步探讨树的演进过程,在一步步引出B树以及为什么MySQL数据库索引选择
书接上回,今天和大家一起动手来自己实现树。 相信通过前面的章节学习,大家已经明白树是什么了,今天我们主要针对二叉树,分别使用顺序存储和链式存储来实现树。 01、数组实现 我们在上一节中说过,
书节上回,我们接着聊二叉树,N叉树,以及树的存储。 01、满二叉树 如果一个二叉树,除最后一层节点外,每一层的节点数都达到最大值,即每个节点都有两个子节点,同时所有叶子节点都在最后一层,则这个
树是一种非线性数据结构,是以分支关系定义的层次结构,因此形态上和自然界中的倒挂的树很像,而数据结构中树根向上树叶向下。 什么是树? 01、定义 树是由n(n>=0)个元素节点组成的
操作系统的那棵“树” 今天从一颗 开始,我们看看如何从小树苗长成一颗苍天大树。 运转CPU CPU运转起来很简单,就是不断的从内存取值执行。 CPU没有好好运转 IO是个耗费时间的活,如果CPU在取值
我想为海洋生物学类(class)制作一个简单的系统发育树作为教育示例。我有一个具有分类等级的物种列表: Group <- c("Benthos","Benthos","Benthos","Be
我从这段代码中删除节点时遇到问题,如果我插入数字 12 并尝试删除它,它不会删除它,我尝试调试,似乎当它尝试删除时,它出错了树的。但是,如果我尝试删除它已经插入主节点的节点,它将删除它,或者我插入数字
B+ 树的叶节点链接在一起。将 B+ 树的指针结构视为有向图,它不是循环的。但是忽略指针的方向并将其视为链接在一起的无向叶节点会在图中创建循环。 在 Haskell 中,如何将叶子构造为父内部节点的子
我在 GWT 中使用树控件。我有一个自定义小部件,我将其添加为 TreeItem: Tree testTree = new Tree(); testTree.addItem(myWidget); 我想
它有点像混合树/链表结构。这是我定义结构的方式 struct node { nodeP sibling; nodeP child; nodeP parent; char
我编写了使用队列遍历树的代码,但是下面的出队函数生成错误,head = p->next 是否有问题?我不明白为什么这部分是错误的。 void Levelorder(void) { node *tmp,
例如,我想解析以下数组: var array1 = ["a.b.c.d", "a.e.f.g", "a.h", "a.i.j", "a.b.k"] 进入: var json1 = { "nod
问题 -> 给定一棵二叉树和一个和,确定该树是否具有从根到叶的路径,使得沿路径的所有值相加等于给定的和。 我的解决方案 -> public class Solution { public bo
我有一个创建 java 树的任务,它包含三列:运动名称、运动类别中的运动计数和上次更新。类似的东西显示在下面的图像上: 如您所见,有 4 种运动:水上运动、球类运动、跳伞运动和舞蹈运动。当我展开 sk
我想在 H2 数据库中实现 B+ Tree,但我想知道,B+ Tree 功能在 H2 数据库中可用吗? 最佳答案 H2 已经使用了 B+ 树(PageBtree 类)。 关于mysql - H2数据库
假设我们有 5 个字符串数组: String[] array1 = {"hello", "i", "cat"}; String[] array2 = {"hello", "i", "am"}; Str
我是一名优秀的程序员,十分优秀!