You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
567 B

#include <litc.h>
void child(int id)
{
int i;
for (i = 0; i < 3; i++) {
printf("hello from %d\n", id);
}
exit(id);
}
int main(int argc, char **argv)
{
int pid = 0;
int id = 0;
while (id < 100) {
pid = fork();
id++;
if (!pid)
child(id);
//if (wait(NULL) != pid)
// errx(-1, "wrong pid %d", pid);
if (wait4(pid, NULL, 0, NULL) != pid)
errx(-1, "wrong pid %d", pid);
if (wait4(pid - 1, NULL, 0, NULL) > 0)
errx(-1, "wait4 should fail");
if (wait(NULL) > 0)
errx(-1, "wait should fail");
}
printf("parent done!\n");
return 0;
}