-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstore.c
More file actions
45 lines (40 loc) · 944 Bytes
/
store.c
File metadata and controls
45 lines (40 loc) · 944 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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include "main.h"
//store info about each background process called
void store(char * name,int pid,int x, char * statement,int ppid)
{
if(x != 0)
{
PROC[p_len].pid = pid;
PROC[p_len].name = name;
PROC[p_len].statement = statement;
PROC[p_len].ppid = ppid;
p_len++;
}
}
void store_pid(int pid,int ppid)
{
char * stat = malloc(MAX_LENGTH*sizeof(char));
char line[MAX_LENGTH];
char p[MAX_LENGTH] ;
sprintf(p, "%d", pid);
strcpy(stat,"/proc/");
strcat(stat,p);
strcat(stat,"/comm");
FILE * fd_input1 = fopen(stat,"r");
if(fd_input1 == NULL)
{
fprintf(stderr, "Failed to open file \n");
return ;
}
fscanf(fd_input1, "%1023s", line);
store(line,pid,1,NULL,ppid);
PROC[p_len-1].stat = 1;
fclose(fd_input1);
free(stat);
return ;
}