Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 打印给定pid的子进程(MINIX)_C_Struct_Operating System_Minix - Fatal编程技术网

C 打印给定pid的子进程(MINIX)

C 打印给定pid的子进程(MINIX),c,struct,operating-system,minix,C,Struct,Operating System,Minix,我目前正在做一个项目,作为项目的一部分,我需要在MINIX中实现系统调用/库函数 作为这项工作的一部分,我需要能够使用给定进程的pid打印给定进程的子进程列表。我想我已经找到了我所需要的一部分,但我一直坚持让它在给定的pid下工作 struct task_struct *task; struct list_head *list; list_for_each(list, &current->children) { task = list_entry(list, stru

我目前正在做一个项目,作为项目的一部分,我需要在MINIX中实现系统调用/库函数

作为这项工作的一部分,我需要能够使用给定进程的pid打印给定进程的子进程列表。我想我已经找到了我所需要的一部分,但我一直坚持让它在给定的pid下工作

struct task_struct *task; 
struct list_head *list;

list_for_each(list, &current->children) { 
    task = list_entry(list, struct task_struct, children); 
}
这看起来和我需要的差不多吗?我知道要传递pid供我使用,我需要使用:

struct task_struct find_task_by_pid(pid_t pid);

但是,我以前从未做过将此与上面的内容相结合的工作。

我发现了这一点,对我来说似乎效率不高,但它确实有效

#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;
}
#包括
#包括“pm.h”
#包括“mproc.h”
int do_printchildpids(){
int i=m_in.m1_i1;//接收到pid
int c=0;//计数器
printf(“搜索进程的子进程:%d\n”,i);
而(c