-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathneonate.c
More file actions
56 lines (52 loc) · 1.24 KB
/
neonate.c
File metadata and controls
56 lines (52 loc) · 1.24 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
#include "headers.h"
void neonate(char *time_halt)
{
int fg_present;
fg_present = 0;
char *hi;
int pid = fork();
if (pid == 0)
{
rawmode();
}
else
{
while (1)
{
unsigned int recent_pid;
FILE *file = fopen("/proc/loadavg", "r");
if (file == NULL)
{
perror("fopen");
return;
}
char buffer[128];
if (fgets(buffer, sizeof(buffer), file) != NULL)
{
sscanf(buffer, "%*f %*f %*f %*d%*c%*d %u", &recent_pid);
}
else
{
printf("Failed to read /proc/loadavg\n");
}
fclose(file);
int normality;
signal(SIGINT, SIG_IGN);
signal(SIGTSTP, SIG_IGN);
pid_t completed_pid = waitpid(pid, &normality, WNOHANG);
if (completed_pid > 0)
{
return;
}
if (recent_pid != 0)
{
printf("%u\n", recent_pid);
}
else
{
printf("No Recent processes found\n");
}
sleep(atoi(time_halt));
}
}
}