first
This commit is contained in:
commit
122205c0d1
2 changed files with 24 additions and 0 deletions
BIN
shell
Executable file
BIN
shell
Executable file
Binary file not shown.
24
shell.c
Normal file
24
shell.c
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
#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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue