/* Orion Lawlor's Short UNIX Examples, olawlor@acm.org 2004/9/5
Shows how to fork()/exec() a child process, in this case 
simply a shell.  fork/exec is more complicated, but much
more flexible and secure than using "system()" to run a process.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h> /* for fork */
#include <sys/types.h> /* for pid_t */
#include <sys/wait.h> /* for wait */

int main()
{
	/*Spawn a child to run the program.*/
	pid_t pid=fork();
	if (pid==0) { /* child process */
		static char *argv[]={"echo","Foo is my name.",NULL};
		execv("/bin/echo",argv);
		exit(127); /* only if execv fails */
	}
	else { /* pid!=0; parent process */
		waitpid(pid,0,0); /* wait for child to exit */
	}
	return 0;
}

/*<@>
<@> ******** Program output: ********
<@> Foo is my name.
<@> */
