-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyshell.c
More file actions
59 lines (53 loc) · 830 Bytes
/
myshell.c
File metadata and controls
59 lines (53 loc) · 830 Bytes
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
51
52
53
54
55
56
57
58
59
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <string.h>
int main()
{
int i,j,k;
while(1)
{
printf("SHELL >>>> ");
char *arglist[10];
j=0;
k=0;
for(i=0;i<10;i++)
arglist[i]=(char *)malloc(10*sizeof(char));
while(1)
{
char ch=getchar();
if(ch==' ')
{
arglist[j][k]='\0';
k=0;
j++;
}
else if(ch=='\n')
{
arglist[j][k]='\0';
break;
}
else
{
arglist[j][k]=ch;
k++;
}
}
arglist[j+1]=NULL;
if(!strcmp(arglist[0],"exit"))
break;
if(!fork())
{
//child
execvp(arglist[0],arglist);
printf("Bad command or file name\n");
exit(0);
}
//parent
wait(NULL);
}
printf("Exiting SHELL\n");
return 0;
}