View Single Post
Old 02-23-2003, 03:44 PM   PM User | #1
makaveli.2003
New Coder

 
Join Date: Jan 2003
Location: UK, England
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
makaveli.2003 is an unknown quantity at this point
Little Program help?

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");
}
makaveli.2003 is offline   Reply With Quote