@@ -54,32 +54,6 @@ static ChildProcess* get_child_process (pid_t pid){
54
54
else return curr -> proc ;
55
55
}
56
56
57
- // Remove the ChildProcess with the given process id from the
58
- // 'child_processes' list if it exists in the list.
59
- // Precondition: SIGCHLD is blocked
60
- static void remove_child_process (pid_t pid ) {
61
-
62
- // Find the ChildProcess with matching pid.
63
- // After this loop, either:
64
- // 1. curr is NULL: No matching ChildProcess was found.
65
- // 2. curr is ChildProcessList*: The matching ChildProcess was found.
66
- volatile ChildProcessList * volatile curr = child_processes ;
67
- volatile ChildProcessList * volatile prev = NULL ;
68
- while (curr != NULL && curr -> proc -> pid != pid ) {
69
- prev = curr ;
70
- curr = curr -> next ;
71
- }
72
-
73
- // Remove child process from list if one was found.
74
- if (curr != NULL ){
75
- if (prev == NULL )
76
- child_processes = curr -> next ;
77
- else
78
- prev -> next = curr -> next ;
79
- //free((void*) curr);
80
- }
81
- }
82
-
83
57
// After a child process is spawned, this function creates a
84
58
// ChildProcess struct for recording the child's metadata
85
59
// and stores it in the 'child_processes' list.
@@ -140,27 +114,17 @@ static void update_child_status (pid_t pid) {
140
114
int ret_pid = waitpid (pid , & status , WNOHANG | WUNTRACED | WCONTINUED );
141
115
142
116
//waitpid returns a positive integer if the process status has changed.
143
- if (ret_pid > 0 ) {
117
+ if (ret_pid > 0 )
144
118
set_child_status (pid , status );
145
- // Remove the child's metadata from list if child is dead.
146
- //if(is_dead_status(status))
147
- // remove_child_process(pid);
148
- }
149
119
}
150
120
151
121
// Update the current status of all registered child processes.
152
122
// Precondition: SIGCHLD is blocked
153
123
static void update_all_child_statuses () {
154
124
volatile ChildProcessList * volatile curr = child_processes ;
155
125
while (curr != NULL ) {
156
- //NOTE: curr->next is retrieved preemptively because
157
- //update_child_status may call free() on curr, and make
158
- //curr->next inaccessible.
159
- //TODO: this is no longer true once update_child_status
160
- // does not call free
161
- volatile ChildProcessList * next = curr -> next ;
162
126
update_child_status (curr -> proc -> pid );
163
- curr = next ;
127
+ curr = curr -> next ;
164
128
}
165
129
}
166
130
0 commit comments