#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

int main(void) {
	int childpid;
	int sleeptime=10;
	char *prog="/usr/bin/vim"; /* try /usr/bin/vim or /bin/sleep */
	char *arg;
	sprintf(arg,"%d",sleeptime);
	char *argv[3]={prog,arg,NULL};

	printf("parend pid: %d\n", getppid());
	childpid=fork();
	if (childpid>0) {
		/* we are the parent */
		/* child is running some program; wait till it is finished */
		printf("Child with pid %d is running\n", childpid);
		waitpid(childpid, 0, 0);
		printf("Child has finished\n");
	} else if (childpid==0) {
		/* Oeh! This is exciting! We are the child! */
		printf("Child with pid %d will do an exec now\n", getpid());
		execve(prog,argv,NULL);
		/* execve doesn't return after prog has exited, so we're dead now :( */
	} else {
		/* some error has occured :( */
	}

	return 0;
}

