159 | | But the process destruction in the owner cluster is more complex, because the child process destruction must be reported to the parent process when the parent process executes the blocking sys_wait() system call. Therefore, the child process destruction cannot be done before the parent calls the sys_wait() function. As the '''sys_wait()''' function, and the '''sys_kill() / sys_exit()''' function are executed by different threads running in different clusters, this requires a parent/child synchronization. |
160 | | |
161 | | After a sys-kill() or sys_exit(), all process threads and all process copies are immediately destroyed, but the process descriptor in owner cluster is kept in ''zombi'' state : the main thread (i.e. thread 0 in process owner cluster) is not deleted until the sys_wait() syscall is executed by the parent process. The synchronization uses the '''term_state''' field in the child process descriptor, that contains the following informations : |
162 | | * the PROCESS_FLAG_KILL flag indicates that a KILL request has been received by the child; |
163 | | * the PROCESS_FLAG_EXIT flag indicates that an EXIT request has been made by the child; |
164 | | * the PROCESS_FLAG_BLOCK flag indicates that a SIGSTOP signal has been received by the child; |
| 159 | But the process destruction in the owner cluster is more complex, because the child process destruction must be reported to the parent process when the parent process executes the blocking sys_wait() system call. Therefore, the child process destruction cannot be done before the parent calls the sys_wait() function. As the '''sys_wait()''' function, and the '''sys_kill() / sys_exit()''' function are executed by different threads running in different clusters, this requires a parent/child synchronization: |
| 160 | After a sys-kill() or sys_exit(), the process descriptor in owner cluster is kept in ''zombi'' state : the main thread (i.e. thread 0 in process owner cluster) is not deleted until the sys_wait() syscall is executed by the parent process. The synchronization uses the '''term_state''' field in the child process descriptor, that contains the following informations : |
| 161 | * the PROCESS_FLAG_KILL indicates that a KILL request has been received by the child; |
| 162 | * the PROCESS_FLAG_EXIT indicates that an EXIT request has been made by the child; |
| 163 | * the PROCESS_FLAG_BLOCK indicates that a SIGSTOP signal has been received by the child; |
168 | | The actual deletion of the process descriptor in owner cluster is done by the sys_wait() function that must be executed by the parent main thread (i.e. thread 0 in parent owner cluster). This sys_wait() function executes an infinite loop. At each iteration the parent scan all children owner descriptors. When it detects that one child terminated, |
169 | | it set the PROCESS_FLAG_WAIT in child descriptor, set the THREAD_FLAG_DELETE in the child main thread, and exit to report the child termination state to parent process. It is the responsibility of the parent process to re-enter the sys_wait() sys call for the other children. When the parent does not detect a terminated child at the end of an iteration, it deschedule without blocking. |
| 167 | The actual deletion of the process descriptor in owner cluster is done by the sys_wait() function, that must be executed by the parent main thread (i.e. thread 0 in parent owner cluster). This sys_wait() function executes an infinite loop. At each iteration the parent scan all children owner descriptors. When it detects that one child terminated, |
| 168 | it set the PROCESS_FLAG_WAIT in child descriptor, set the THREAD_FLAG_DELETE in the child main thread, and exit to report the child termination state to parent process. It is the responsibility of the parent process to re-enter the sys_wait() syscall for the other children. When the parent process does not detect a terminated child at the end of an iteration, it deschedules without blocking. |
174 | | 1. Both the sys_kill() or sys_exit() sys calls, use the rpc_process_make_kill_client(), to ask an RPC thread to execute the process_make_kill() function in the owner cluster (because a thread cannot delete itself). |
175 | | 1. The process_make_kill() function in owner cluster send a multicast and parallel RPC to all clusters containing a copy of the process. In each cluster, the process_block_threads() function set the BLOCKED_GLOBAL bit for all threads of the process. It returns only when all threads are blocked and descheduled. |
176 | | 1. When the process_make_kill() function in owner cluster has received all expected responses to the first multicast RPC, it send another multicast and parallel RPC to all clusters containing a copy of the process. In each cluster, the process_delete_threads() function releases the memory allocated to all local threads but the process main thread (thread 0 in owner cluster). All process descriptors copies are destroyed, but the one in owner cluster. |
177 | | 1. When the process_make_kill() function in owner cluster has received all expected responses to the second multi-cast RPC, it updates the owner cluster manager |
178 | | to remove the process from the set of owned processes. |
179 | | 1. Finally, the process_make_kill() function synchronizes with the parent process, and the parent sys_wait() function delete the process descriptor in owner cluster. |
| 173 | This section describes the termination of a process caused by a sys_exit(). |
| 174 | |
| 175 | 1. The sys_exit() syscall must be executed by the main thread of the calling process( i.e. thread 0 in owner cluster), |
| 176 | 1. The sys_exit() function calls the process_sigaction() function that send a multicast, parallel and non blocking RPC to all clusters containing at least one thread of the calling process, to block all process threads, but the main (calling) thread. This function returns only when all threads (but the main) are blocked and descheduled. |
| 177 | 1. The sys_exit() function calls again the process_sigaction() function that send another multicast, parallel and non blocking RPC to the same clusters, to mark for delete all process threads, but the main (calling) thread. The marked threads will be actually destroyed by the scheduler at the next scheduling point. The remote process descriptor copies are actually destroyed by the scheduler when the last thread in remote cluster is destroyed. |
| 178 | 1. The sys_exit() function set the PROCESS_TERM_EXIT flag in owner process descriptor to synchronize with the parent process, and deschedules. |
| 179 | 1. This main thread, and the process descriptor in owner cluster will be actually destroyed by the scheduler when the parent process sys_wait() function marks this main thread for delete. |
| 180 | |
| 181 | === 6.3) detailed kill scenario === |
| 182 | |
| 183 | This section describes the termination of a target process caused by a sys_kill( SIGKILL ). |
| 184 | |
| 185 | 1. The sys_kill() syscali must be executed by the main thread of the target process OR by any thread of another process than the target process. |
| 186 | 1. The sys_kill() function calls the process_sigaction() function that send a multicast, parallel and non blocking RPC to all clusters containing at least one thread of the target process, to block all process threads, but the main thread. This function returns only when all threads (but the main) are blocked and descheduled. |
| 187 | 1. The sys_kill() function calls again the process_sigaction() function that send another multicast, parallel and non blocking RPC to the same clusters, to mark for delete all process threads, but the main thread. The marked threads will be actually destroyed by the scheduler at the next scheduling point. The target process descriptor copies are actually destroyed by the scheduler when the last thread in remote cluster is destroyed. |
| 188 | 1. The sys_kill() function set the PROCESS_TERM_KILL flag in the target process descriptor in owner cluster to synchronize with its parent process, and returns. |
| 189 | 1. The target process main thread, and the target process descriptor in owner cluster will be actually destroyed by the scheduler when the parent process sys_wait() function marks this main thread for delete. |