28 lines
488 B
C
28 lines
488 B
C
#include <unistd.h>
|
|
#include <sys/wait.h>
|
|
|
|
int real_waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options, void*);
|
|
|
|
int main()
|
|
{
|
|
char command[255];
|
|
for (;;) {
|
|
write(1, "# ", 2);
|
|
int count = read(0, command, 255);
|
|
// /bin/ls\n -> /bin/ls\0
|
|
command[count - 1] = 0;
|
|
pid_t fork_result = fork();
|
|
if (fork_result == 0) {
|
|
execve(command, 0, 0);
|
|
break;
|
|
} else {
|
|
// wait
|
|
//
|
|
siginfo_t info;
|
|
real_waitid(P_ALL, 0, &info, WEXITED, 0);
|
|
}
|
|
}
|
|
|
|
_exit(0);
|
|
}
|