I have to write a script creating processes tree using fork() function. Then I need to use the exec() function inside the script, to generate only ONE processes tree, with pstree -c command.
Ok, so I created processes tree, that's not a problem, let's say:
int main() {
int pid1, pid2;
if(pid1 = fork()) {
printf("%d", pid1);
} else if (pid2 = fork()) {
printf("%d", pid2);
} else {
printf("%s", "parent process");
}
return 0;
}
But how do I use exec function to invoke pstree -c command? And how can I show only one specific tree?
execl("/bin/pstree -c", "pstree -c", 0, 0);
I tried with /bin/, without it...nothing works, the tree is not displayed when I run the script.
And it would display the whole tree anyways, not just the forks I used.
How can I do that?
Aucun commentaire:
Enregistrer un commentaire