minimake/microshell/microshell.c

31 lines
564 B
C
Raw Normal View History

2025-10-23 17:36:07 +02:00
#include <err.h>
2025-10-23 19:03:00 +02:00
#include <stdio.h>
2025-10-23 17:36:07 +02:00
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>
int main(int argc, char **argv)
{
if (argc < 2)
2025-10-23 19:03:00 +02:00
err(1, "Not enough args");
2025-10-23 17:36:07 +02:00
int id = fork();
if (id < 0)
2025-10-23 19:03:00 +02:00
err(1, "Cannot fork");
2025-10-23 17:36:07 +02:00
if (id == 0)
{
int res = 0;
wait(&res);
2025-10-23 19:03:00 +02:00
// printf("%d\n", res);
2025-10-23 17:36:07 +02:00
return res;
}
else
{
int res = execl("/bin/sh", "supershell", "-c", argv[1], NULL);
2025-10-23 19:03:00 +02:00
printf("process exit status: %d\n", res);
// exit(res);
return res;
2025-10-23 17:36:07 +02:00
}
}