Der richtige Source sieht so aus:
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#define BUFFERSIZE 100
int main() {
char line[10];
int count = 0;
while( 1 ) {
printf( "Befehlscode eingeben: " );
fgets( line, BUFFERSIZE, stdin );
if( line[0] == '0' ) {
break;
}
if( fork() == 0 ) {
count++;
if( line[0] == '1' ) {
execlp( "ls", "ls", "-li", (char*)NULL );
} else if( line[0] == '2' ) {
execlp( "ps", "ps", "-H", (char*)NULL );
} else if( line[0] == '3' ) {
execlp( "ln", "ln", "x", "y", (char*)NULL );
} else if( line[0] == '4' ) {
execlp( "nonexistent", "x", "y", (char*)NULL );
}
perror( "FEHLER" );
exit( errno );
}
int status;
wait(&status);
}
printf( "Anzahl der ausgefuehrten Befehle: %d\n", count );
return 0;
}
Um unter linux das Programm zu kompilieren:
gcc -Wall program.c -o program
./program
1-4 als Option
Aber was soll dir das Programm zeigen.
Warum nicht einfach die MAN page anschauen:
man ps
man ls
man ln
PS: Prozesslisting mit optionen
LS: Directory listing mit optionen
ln: symlink (Verkünpfung)
lg. FHMER
|