Hi, I don't know why when i run this code with redirection of output, , it seems that the process child is not adopted by init.
Code:
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <ctype.h>
static void ex1(void)
{
printf("student\n");
}
static void ex2(void)
{
printf("prof \n");
}
int main(void)
{
pid_t pid1,pid2;
int s=0, c;
pid1=fork();
if (pid1==0) {
atexit(ex1);
atexit(ex2);
while ((c=getppid()) != 1) {
printf("pid=%d\n", c);
s=s+1;
printf("userc: %d\n",s);
exit(0);
}
}
else {
atexit(ex1);
atexit(ex2);
printf("userf: %d\n",s);
exit(0);
}
}