- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在破解 linux 内核并与 struct task_struct current
的 sibling 和 child 一起玩。
当输出 sibling 的pid
和命令名时,似乎有一个格式错误的进程,pid
= 0
,命令名是胡言乱语。
进程的父进程也会发生同样的事情。
为什么兄弟之间出现pid=0
的进程?那个进程不是为 swapper
保留的吗?
// Loop over process and parents using something like:
/*
printk("--syscall ## Begin process results ##");
printk("--syscall // View children //");
my_list_head = &(current->children);
printk("--syscall // View siblings //");
my_list_head = &(current->sibling)
printk("--syscall results: ...");
*/
if (my_list_head == NULL) {
return 0;
}
list_for_each(tempNode, my_list_head) {
tempTask = list_entry(tempNode, struct task_struct,
sibling);
printk("--syscall The %ld-th process's pid is %d and command %s",
count, tempTask->pid, tempTask->comm);
}
带空格的格式
[ 2938.994084] --syscall ## Begin process results ##
[ 2938.994089] --syscall // View children //
[ 2938.994105] --syscall // View siblings //
[ 2938.994116] --syscall The 1-th process's pid is 0 and command \x80ݶE\x96\xff\xff
[ 2938.994133] --syscall results: pid=1400 name=process_ancesto state=0 uid=1000 nvcsw=1 nivcsw=0 num_children=0 num_siblings=1
[ 2938.994139] --syscall ## Begin process results ##
[ 2938.994144] --syscall // View children //
[ 2938.994149] --syscall The 1-th process's pid is 1400 and command process_ancesto
[ 2938.994158] --syscall // View siblings //
[ 2938.994163] --syscall The 1-th process's pid is 0 and command
[ 2938.994176] --syscall results: pid=1282 name=bash state=1 uid=1000 nvcsw=88 nivcsw=18 num_children=1 num_siblings=1
[ 2938.994180] --syscall ## Begin process results ##
[ 2938.994185] --syscall // View children //
[ 2938.994190] --syscall The 1-th process's pid is 1282 and command bash
[ 2938.994198] --syscall // View siblings //
[ 2938.994203] --syscall The 1-th process's pid is 1275 and command systemd
[ 2938.994210] --syscall The 2-th process's pid is 0 and command
[ 2938.994216] --syscall The 3-th process's pid is 117 and command systemd-journal
[ 2938.994222] --syscall The 4-th process's pid is 145 and command systemd-udevd
[ 2938.994227] --syscall The 5-th process's pid is 148 and command systemd-network
[ 2938.994233] --syscall The 6-th process's pid is 369 and command systemd-resolve
[ 2938.994239] --syscall The 7-th process's pid is 370 and command systemd-timesyn
[ 2938.994245] --syscall The 8-th process's pid is 412 and command accounts-daemon
[ 2938.994321] --syscall The 9-th process's pid is 413 and command dbus-daemon
[ 2938.994336] --syscall The 10-th process's pid is 417 and command irqbalance
[ 2938.994346] --syscall The 11-th process's pid is 418 and command rsyslogd
[ 2938.994352] --syscall The 12-th process's pid is 419 and command snapd
[ 2938.994359] --syscall The 13-th process's pid is 420 and command systemd-logind
[ 2938.994365] --syscall The 14-th process's pid is 439 and command cron
[ 2938.994372] --syscall The 15-th process's pid is 451 and command atd
[ 2938.994378] --syscall The 16-th process's pid is 456 and command agetty
[ 2938.994385] --syscall The 17-th process's pid is 461 and command sshd
[ 2938.994390] --syscall The 18-th process's pid is 491 and command unattended-upgr
[ 2938.994397] --syscall The 19-th process's pid is 501 and command polkitd
[ 2938.994413] --syscall results: pid=1200 name=login state=1 uid=0 nvcsw=31 nivcsw=33 num_children=1 num_siblings=19
最佳答案
下面是两个同胞子进程如何链接到其父进程的子进程列表的说明:
PARENT CHILD 1 CHILD 2
====== ======= =======
task_struct task_struct
+-------------+ +-------------+
| | | |
task_struct ~ ~ ~ ~
+-------------+ | | | |
| | |-------------| |-------------|
~ ~ | children | | children |
| | | | | |
. . |-------------| . . |-------------| . . |-------------| . .
| children | | sibling | | sibling |
X==>| prev | next |<===>| prev | next |<===>| prev | next |<==X
. . |-------------| . . |-------------| . . |-------------| . .
| sibling | | | | |
| | ~ ~ ~ ~
|-------------| | | | |
| | +-------------+ +-------------+
~ ~
| | 'X's are joined together, making
+-------------+ a doubly linked, circular list.
尽管 children
和 sibling
都是 struct list_head
类型,但是 children
被用作实际列表head(链接到它的子进程列表),而 sibling
被用作列表条目。
parent 的 children.next
链接指向 child 1 的 sibling
成员, child 1 的 sibling.next
链接指向 child 2 的 sibling
成员,而 child 2 的 sibling.next
链接指向父级的 children
成员(列表头)。类似地, parent 的 children.prev
链接指向 child 2 的 sibling
成员, child 2 的 sibling.prev
链接指向 child 1 的 兄弟
成员,子 1 的 sibling.prev
链接指向父级的 children
成员。
list_for_each(pos, head)
宏访问列表中的每个节点 pos
,从 head->next
开始,而 pos != 头
。
通常情况下,list_for_each(pos, head)
的head
参数应该是一个真正的链表头,但是宏无法区分链表头和链表入口。它们都是同一类型,所有节点都循环链接在一起。 (整个列表由一个列表头组成,其中零个或多个列表条目链接成一个圆圈。对于空列表,列表头仅链接回自身。)list_for_each
宏将围绕双向链表,直到它回到它开始的地方。
如果调用 list_for_each(pos, head)
时 head
指向父级的 children
成员,则 pos
将在第一次迭代中指向 child 1 的 sibling
成员,并在第二次迭代中指向 child 2 的 sibling
成员,并使用 pos 终止循环
指向父级的 children
成员。在循环内,list_entry(pos, struct task_struct, sibling)
将正确指向子进程的 struct task_struct
的开头。
假设子进程 1 是当前
进程。 OP 的代码使用 list_for_each(pos, head)
和 head
指向 child 1 的 sibling
成员。因此,pos
将在第一次迭代中指向 child 2 的 sibling
成员,并在第二次迭代中指向父级的 children
成员,并且将终止循环,pos
指向子 1 的 sibling
成员。在循环内部,list_entry(pos, struct task_struct, sibling)
会在第一次迭代中正确指向 child 2 的 struct task_struct
的开头,但是 pos
将指向在第二次迭代中父级的 struct task_struct
开始之前的某个位置。这就是问题出在 OP 代码中的地方。
关于c - `struct task_struct current` 的兄弟总是包含一个 `pid = 0` 的进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67119348/
我的目标是运行类似 bro --iface 的命令并只获取 conn.log,但我无法从 Bro 文档或联机帮助页中得知如何执行此操作。 谢谢。 最佳答案 这让你继续: bro -i -b b
我正在使用以下 jQuery 来更改无序列表中元素的类。这似乎不是实现该效果的最有效方法。有更好的写法吗? $(function() { $('nav li a').click( functi
我有一个看起来像这样的导航栏 Services Work Contact 当我 :hover 一项时,我想更改其他两项的样式。我可以使用什么 CSS 选择器? 最佳答案 您
我正在寻找一种方法来选择包含特定图像的列的行内具有特定名称属性的所有输入。 下面的代码是一个说明性示例:
假设我有以下 HTML: 我想在鼠标悬停在元素上时对图标应用一些规则,可以用以下 CSS 描述: .navigation__item__icon { color: black; } .n
我的 div text-button 没有与我在其兄弟 div 下想要的正确边距对齐。我将 position: absolute; 设置到位,因为每次我将其设置为相对位置时,jQuery 动画都不起作
这个问题在这里已经有了答案: CSS margin terror; Margin adds space outside parent element [duplicate] (7 个答案) 关闭
如果我有 3 个 NSManagedObjectContext。 一个。是根上下文。 B.是一个后台保存上下文,解析一个JSON后生成NSManagedObjects C.是在 NSFetchedRe
我在容器中有三个 div:http://jsfiddle.net/fBe9y/ 一个div内容很多。如何让内容较少的其他两个 div 与最长的 div 的高度匹配? 我尝试将 height: 100%
我正在尝试通过单击另一个元素对一个元素执行一个简单的 toggleClass。有多个元素具有相同的类,我只想切换同级/最近的元素。我相信我从根本上理解了针对 parent / child / sibl
我正在使用 AngularJS 开发一个小应用程序。我的项目包含一个包含 3 个 View 的 Body.html 文件:SideMenu、Header 和 Content,每个 View 都有自己的
在 CSS 方面,我不认为我是个笨蛋,但这个就是我。我的想法是我需要一个父元素,两侧有两个 float 子元素。我希望 parent 的高度与 child 的高度一样高,并让 child 的高度变得相
我有两个 span(s) 在父级 div 中彼此相邻。 我希望第二个 span 显示在最左边,然后是第一个 span。 (注意:由于某些原因,我不能简单地移动第二个跨度来代
今天跟大家分享下selenium中根据父子、兄弟、相邻节点定位的方法,很多人在实际应用中会遇到想定位的节点无法直接定位,需要通过附近节点来相对定位的问题,但从父节点定位子节点容易,从子节点定位父节点
这是 HTML 的结构:
我在一个包装器中并排放置了两个 div。其中一个 div 的内容比另一个多,我希望第二个 div 填充包装的垂直空间。 .wrapper { height: 50%; width: 50%;
我的网站顶部有一个带有此 CSS 的菜单: .menu { width: 100%; display: block; float: left; } 在里面,我有几个 div: .menu .menu-
我有两个 div 元素,第一个 div 中有一个按钮,如下所示。 Click 下面是我的 JavaScript 代码。 function nextDiv(el
两个同级 div(#one 和 #two),每个都包含一些文本。 我移动#two margin-top 为负,预计它会覆盖 #one , 但当文本位于 #one 前面时,背景位于下方。 只有在 #on
我有一个容器 div,它有一个 float 的左侧导航 Pane 和一个右侧的内容 Pane : CSS: body { text-align: cent
我是一名优秀的程序员,十分优秀!