-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyShell.c
More file actions
64 lines (57 loc) · 1.08 KB
/
myShell.c
File metadata and controls
64 lines (57 loc) · 1.08 KB
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
60
61
62
63
64
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<string.h>
#include<signal.h>
#include"shellfunc.c"
#include"shellread.c"
void handlerint(int sig)
{
char msg[]="the program is interrupted, do you want to exit [Y/N]";
write(1,msg,53);
char response[1];
int r = read(0,response,1);
if(r==1 && response[0]=='Y'){
fflush(stdout);
exit(0);
}
}
void handlerterm(int sig)
{
char msg[]="Got SIGTERM-Leaving";
write(1,msg,19);
exit(0);
}
int main(int argc, char *argv[])
{
while(1)
{
signal(SIGINT, handlerint);
signal(SIGTERM, handlerterm);
char msg[]="myShell> ";
write(1,msg,10);
char input[1000];
int c = read(0,input,1000);
if(input[0]=='\n'){
continue;
}
input[c-1]='\0';
int q=0,read_flag=0;
while(input[q]!='\0'){
if(!(input[q]==' ')){
read_flag=1;
break;
}
q++;
}
if(read_flag==0){
continue;
}
if(strcmp(input,"exit")==0){
exit(0);
}
shellread(input);
}
}