1
0
Files
Laboratori-OS/Lab02/executor.c
2024-03-22 16:54:05 +01:00

31 lines
431 B
C

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define LEN 128
#define USE_LIB 0
int main(int argc, char ** argv) {
FILE *flist;
if (argc < 2) return 1;
flist = fopen(argv[1], "r");
char cmd[LEN];
while(fgets(cmd, LEN, flist)) {
if (USE_LIB) {
system(cmd);
continue;
}
if (!fork()) {
execl("/bin/sh", "sh", "-c", cmd, (char *) NULL);
} else {
sleep(3);
}
}
return 0;
}