-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRestrictedShell.c
More file actions
93 lines (80 loc) · 1.41 KB
/
RestrictedShell.c
File metadata and controls
93 lines (80 loc) · 1.41 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sys/types.h>
#include<signal.h>
#include<sys/wait.h>
#include<time.h>
int main(int argc,char *argv[])
{
int response;
FILE *fp;
char line[256];
response_pid pid1;
response_pid pid2;
if(strcmp(argv[1],"list")==0)
{
fp=fopen("pidlist","r");
char line[256];
while(fgets(line,sizeof line,fp)!=NULL)
{
printf("%s\n",line);
}
}
else if(strcmp(argv[1],"sleep1")==0)
{
pid1=fork();
if(pid1==0)
{
printf("child process created and sleeping",getpid(pid1),n);
printf(fp,"%d\n",getpid(pid1));
fclose(fp);
}
}
else if(strcmp(argv[1],"kill1")==0)
{
response_pid y=atoi(argv[2]);
int response=kill(y,SIGINT);
printf("%d",response);
}
else if(strcmp(argv[1],"time1")==0)
{
response_pid x=atoi(argv[2]);
char command[256];
FILE *fp;
char *tp;
printf(command,"ps |grep %d",x);
fp=popen(command,"r");
printf("%s",command);
char line[256];
while(fgets(line,sizeof line,fp))
{
tp=strtok(line, "\t");
}
while(tp !=NULL)
{
tp=strtok(NULL, "\t");
printf("Time %s\n",tp);
}
}
return 0;
}
void update(FILE *fp,char *line,char *pid2,response_pid pid1)
{
fp=fopen("pidlist","r");
char pline[256];
int count=0;
while(fgets(line,sizeof line,fp))
{
scanf(line,"%s",pid2);
if(pid1==0)
{
printf(pline,"%d",getpid(pid1));
}
else
{
printf(pline,"%d",pid1);
}
}
fclose(fp);
}