Im new to C Programming and have been workin on afew examples off the internet, but I cant seem to work out what these 2 programs do, could some1 please tell me what these programs do, and help me understand what each line does? plz, thx in advance.
Code:
main()
{
printf("My pid = %d. My parent's pid = %d\n", getpid(), getppid());
}
Code:
fatal(s)
char *s;
{
perror(s);
exit(1);
}
main()
{
int pid;
pid = fork();
printf("The PID is %d\n",pid);
if(pid > 0)
{
wait((int *)0);
printf("ls completed\n");
exit(0);
}
if (pid == 0)
{
execl("/bin/ls", "ls", "-l", (char *)0);
fatal("execl failed");
}
fatal("fork failed");
}