-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
executable file
·120 lines (116 loc) · 3.23 KB
/
main.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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include "headers.h"
#include "prompt.h"
#include "clean.h"
#include "divider.h"
#include "caller.h"
#include "peek.h"
#include "proclore.h"
#include "sys/wait.h"
#include "sys/types.h"
#include <signal.h>
char *Pardir;
char *past;
int ttiimmee;
char *command;
char **store1;
int idontchar = 0;
Node *listlist = NULL;
struct Information *listofproc = NULL;
int ss = 0;
void custsig(int signum)
{
return;
}
void sina(int signum)
{
if (idontchar == 0)
return;
int targetPID = idontchar;
if (kill(targetPID, SIGSTOP) == -1)
{
perror("kill");
// exit(1);
}
idontchar = 0;
// Add any additional actions you want to perform here
}
int main()
{
signal(SIGINT, SIG_IGN);
signal(SIGTSTP, SIG_IGN);
signal(SIGTTOU, SIG_IGN);
if (signal(SIGINT, custsig) == SIG_ERR)
{
perror("signal");
return 1;
}
if (signal(SIGTSTP, sina) == SIG_ERR)
{
perror("signal");
// exit(1);
}
printf("\n\n");
printf("\033[H\033[J");
Pardir = (char *)malloc(sizeof(char) * (1024));
past = (char *)malloc(sizeof(char) * (1024));
command = (char *)malloc(sizeof(char) * (1024));
getcwd(Pardir, 1024);
getcwd(past, 1024);
int n = 1e5;
store1 = (char **)malloc(sizeof(char *) * n);
for (int i = 0; i < n; i++)
{
store1[i] = (char *)malloc(sizeof(char) * (1024));
}
while (1)
{
// Print appropriate prompt with username, systemname and directory before accepting input
prompt(Pardir);
ss = 0;
char *input = (char *)malloc(sizeof(char) * (4096));
if (fgets(input, 4096, stdin) == NULL)
{
ss = 0;
while (listofproc != NULL)
{
struct Information *x = listofproc;
listofproc = listofproc->nextnode;
if (kill(x->pid, 9) != 0)
{
perror("kill");
return 1;
}
else
{
printf("Signal %d sent to process with PID %d\n", 9, x->pid);
// printf("Mar gaya\n");
}
// kill(x->pid, 9);
listofproc = removeProcess(listofproc, x->pid);
}
// printf("\n");
exit(0);
}
Node *currentNode = listlist;
while (currentNode != NULL)
{
if ((((currentNode->stat) & 0x7f) == 0))
{
printf("process %s [PID] : %d exited normally with status %d\n", store1[currentNode->procPid], currentNode->procPid, WEXITSTATUS(currentNode->stat));
store1[currentNode->procPid] = NULL;
}
else if ((((signed char)(((currentNode->stat) & 0x7f) + 1) >> 1) > 0))
{
printf("process %s [PID] : %d exited abnormally due to signal %d\n", store1[currentNode->procPid], currentNode->procPid, WTERMSIG(currentNode->stat));
store1[currentNode->procPid] = NULL;
}
Node *temp = currentNode;
currentNode = currentNode->next;
free(temp);
}
listlist = NULL;
input = clean(input);
divider(input);
}
printf("\n\n");
}