-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdelete.c
More file actions
57 lines (51 loc) · 1.01 KB
/
delete.c
File metadata and controls
57 lines (51 loc) · 1.01 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
#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>
#include "helper.h"
#include "builtin.h"
Node * head, * end, * lead, * follow;
extern int status;
void main_delete(pid_t proc_id)
{
if(head->next != NULL)
follow = head->next;
if(follow != NULL && follow->next != NULL && follow->pid != proc_id)
{
lead = follow->next;
while(lead != NULL)
{
if(lead->pid == proc_id)
{
printf("%s [%d] %d\n", lead->pname, proc_id, WEXITSTATUS(status));
if(lead->next == NULL)
end = follow;
follow->next = lead->next;
free(lead);
break;
}
else
{
follow = lead;
lead = follow->next;
}
}
return;
}
else if(follow != NULL && follow->pid == proc_id)
{
printf("%s [%d] %d\n", follow->pname, proc_id,WEXITSTATUS(status));
head->next = follow->next;
if(head->next == NULL)
end = head;
free(follow);
return;
}
return;
}