All pastes #513854 Raw Edit

Something

public text v1 · immutable
#513854 ·published 2007-05-27 13:20 UTC
rendered paste body
/*
 * Systemmanagement und Sicherheit
 * Uebung 2
 * 
 * Philip Schneider
 *
 * Beschreibung: Fork, Exec
 *
 * Aufruf:  ./start programmname argument1 argument2 argument3
 * Bsp:		./start ls -l
 */

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

/* http://www.pronix.de/pronix-162.html */
/* http://www.csl.mtu.edu/cs4411/www/NOTES/process/fork/create.html */

int main(int argc, char** argv){
	
	/* Variablen anlegen */
 	/* pid_t pid; */
	
	/* Sohnprozess erzeugen */
	/* fork(); */
		
	switch(fork()){
		case 0:	{
			/* child code */
			printf("Child Code ...\n");
			
			/* ProcessID des Sohnprozesses abfragen */
			/* pid = getppid(); */
			printf("PID = %d\n",getppid());
						
			/* Ausfuehren des Programms (argv[1], mit den in argv[2 ... ] stehenden argumenten */
			return execvp(argv[1],argv+2); 
				}
			break;
		case -1: {
			/* fehlerbehandlung */
			printf("Fehlerbehandlung ...\n");
		}
			break;
		default: {
			/* parent code */
			/* printf("Parent Code ...\n"); */
		}
			break;
	}
	
	return 0;
}