Hello. Please help with the following question.
Write a simple daemon.
int main() {
int pid = 0, ppid = 0;
ppid = fork(); //1
if(ppid<0)
exit(1);
chdir("/"); //2
pid = setsid();//3
//4
demon();
printf("%d\n", pid);
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
return 0;
}
And want to get its PID. But
printf("%d\n", pid) Outputs I, for some reason, number 2: PID of parent and 1.
Hence two questions. Why do I displays 2 numbers, although
printf("%d\n", pid) one? What am I doing wrong when creating the demon?
int ppid = 0;
ppid = fork();
if(ppid==0){
printf("Hello\n");
}
return 0;
}
Quite everything works - dariana_Sauer commented on July 9th 19 at 11:13