-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path32184594_myshell.c
50 lines (44 loc) · 1.15 KB
/
32184594_myshell.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* makeShell.c
*@author: Seongjin Choi
*@email : [email protected]
*version = 1.0
*date = 22.12.09
**/
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/wait.h>
#include <sys/types.h>
#define MAX 100
int main(int argc, char **argv)
{
char buffer[MAX];
pid_t pid;
printf("나만의 쉘 시작(exit 입력시 종료)");
while(1)
{
memset(buffer, 0x00, MAX);
fgets(buffer, MAX - 1, stdin);
if(strncmp(buffer, "exit\n", 5) == 0)
{
break;
}
buffer[strlen(buffer) - 1] = 0x00;
pid = fork();
if(pid == 0)
{
if(execlp(buffer, buffer, NULL) == -1)
{
printf("Failed \n");
exit(0);
}
}
if(pid > 0)
{
wait(NULL);
}
}
return 0;
}