我目前正在处理一个项目,作为其中的一部分,我需要在MINIX中实现系统调用/库函数。
作为其中的一部分,我需要能够使用其pid打印给定进程的子进程列表。我想我已经找到了我需要的部分内容,但是我仍然坚持使用给定的pid工作。
function mapDispatchToProps(dispatch) {
return bindActionCreators({
selectUser: selectUser
}, dispatch);
}
export default connect(mapStateToProps, mapDispatchToProps)(UserList);
这看起来像我需要的东西吗?我知道,为了让我使用pid,我需要使用:
struct task_struct *task;
struct list_head *list;
list_for_each(list, ¤t->children) {
task = list_entry(list, struct task_struct, children);
}
但是,将此与上述相结合并不是我之前所做过的事情。
答案 0 :(得分:1)
我想通了,对我来说似乎没那么高效但是有效。
#include <stdio.h>
#include "pm.h"
#include "mproc.h"
int do_printchildpids(){
int i = m_in.m1_i1; //pid received
int c = 0; //Counter
printf("Searching for children of process: %d \n", i);
while (c < NR_PROCS)
{
int n = mproc[c].mp_pid; //First process in the list of availableprocess
int pinx = mproc[c].mp_parent; //Index of parent of the current process
int ppid = mproc[pinx].mp_pid; //pid of parent process
if(i == ppid) //If parents pid matches the given value
{
printf("%d \n", n); //Print the childs id
c++;
}
else
{
c++;
}
}
return -1;
}