can anyone explain this programing codes?
proc1.c
#include <stdio.h>
int main()
{
int fork_return;
fork_return = fork();
printf("PID=%d, PPID=%d, fork_return=%d\n", getpid(), getppid
(), fork_return);
sleep(10); /* wait for 10 sec */
return 0;
}
proc2.c
#inlcude <stdio.h>
int main()
{
int chpid=fork();
if (chpid < 0)
{
printf("ERROR\n");
exit(1);
}
else if(chpid == 0)
{
printf("Child process: ");
printf("PID=%d, PPID=%d\n", getpid(), getppid());
sleep(10); /* waits 10 sec */
}
else
{
printf("Parent process: ");
printf("PID=%d, PPID=%d\n", getpid(), getppid());
sleep(10); /* waits 10 sec */
}
return 0;
}