24 lines
455 B
C
24 lines
455 B
C
#include <sys/wait.h>
|
|
#include <unistd.h>
|
|
|
|
int main() {
|
|
char command[255];
|
|
|
|
while (1) {
|
|
write(1, "benag@shell > ", 14);
|
|
int count = read(0, command, 255);
|
|
// /bin/ls\n -> /bin/ls\0
|
|
command[count - 1] = 0;
|
|
|
|
char *args[] = {command, NULL};
|
|
pid_t fork_result = fork();
|
|
|
|
if (fork_result == 0) {
|
|
execve(command, args, 0);
|
|
break;
|
|
} else {
|
|
siginfo_t info;
|
|
waitid(P_ALL, 0, &info, WEXITED);
|
|
}
|
|
}
|
|
}
|