Étant donné un ID de processus transmis à l'appel système, j'ai besoin de renvoyer tous les ID de processus enfant. Cela doit être écrit en C. J'ai utilisé mproc pour obtenir le processus parent d'un pid d'enfant et lister tous les processus d'un index donné, mais je ne peux pas faire le saut entre ça et ça.C programme pour obtenir des ID de processus enfant à partir d'un ID parent uniquement (minix)
Mon code:
int do_getchildpids() {
// get pid from parameter
int ppid = m_in.m1_i1;
// Get the child pid of this process
pid_t cpid;
if (cpid == fork()) {
printf("Child pid for ppid %d is %d\n", ppid, getpid());
}
// ** Other attempt at this problem below **
// if mp_parent == ppid then print pid
int idx = 0;
int cpid = mproc[idx].mp_pid;
while (mproc[idx].mp_pid) {
idx++;
}
printf("Searching for children of %d...\n", ppid);
if (pid == 0) {
// for loop that gets the ppid, checks against given ppid
// prints out pid if true
if (cpid) {
// loop through proc table checking if ppid is equal to parameter passed
if (ppid == mproc[mproc[i].mp_parent].mp_pid)
printf("Child pid is %d.\n", getpid());
}
printf("Child pid is: %d.\n", getpid());
} else {
printf("Error, child pid was not set or is -1\n");
}
return 0;
}
Ne commentez pas le code que vous voulez nous aider, la syntaxe surligneur le rend difficile à lire. – Barmar
@Barmar apologies - édité. – Jimmy