Zurück zur SPiC Übersicht
run.c
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
static void die(const char *msg) {
perror(msg);
exit(EXIT_FAILURE);
}
int main(int argc, char *argv[]) {
for (int i = 2; i < argc; i++) {
printf("Programm wird gestartet: %s mit Paramter %s\n", argv[1], argv[i]);
pid_t p = fork();
if (p < 0) {
die("fork");
}
if (p == 0) {
execlp(argv[1], argv[1], argv[i], NULL);
die(argv[1]);
}
int status;
pid_t c = waitpid(-1, &status, 0);
if (c < 0) {
die("waitpid");
}
if (WIFEXITED(status)) {
printf("exit mit %d\n", WEXITSTATUS(status));
} else if (WIFSIGNALED(status)) {
printf("signal mit %d\n", WTERMSIG(status));
}
}
}