-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete.c
More file actions
58 lines (56 loc) · 1.07 KB
/
Copy pathdelete.c
File metadata and controls
58 lines (56 loc) · 1.07 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
#include <sys/wait.h>
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <signal.h>
typedef struct Node{
pid_t pid_process;
char pname[100];
int num;
struct Node *next;
}node;
node * head, * end, * lead, * follow;
extern int childStatus;
extern int counter;
extern node * head;
//function to delete background processes from link list
void delete(pid_t p_id)
{
if(head->next != NULL)
follow = head->next;
if(follow!=NULL)
{
if(follow->next != NULL && follow->pid_process != p_id)
{
lead = follow->next;
while(lead != NULL)
{
if(lead->pid_process == p_id)
{
printf("%s [%d] %d\n", lead->pname, p_id, WEXITSTATUS(childStatus));
follow->next = lead->next;
free(lead);
break;
}
else
{
follow = lead;
lead = follow->next;
}
}
return;
}
else if(follow->pid_process == p_id)
{
printf("%s [%d] %d\n", follow->pname, p_id,WEXITSTATUS(childStatus));
head->next = follow->next;
free(follow);
return;
}
}
}