Index: trunk/kernel/kern/process.h
===================================================================
--- trunk/kernel/kern/process.h	(revision 428)
+++ trunk/kernel/kern/process.h	(revision 433)
@@ -4,5 +4,5 @@
  * Authors  Ghassan Almaless (2008,2009,2010,2011,2012)
  *          Mohamed Lamine Karaoui (2015)
- *          Alain Greiner (2016,2017)
+ *          Alain Greiner (2016,2017,2018)
  *
  * Copyright (c) UPMC Sorbonne Universites
@@ -65,14 +65,13 @@
 
 /*********************************************************************************************
- * This enum defines the process states for ALMOS_MKH.
- ********************************************************************************************/
-
-enum process_states
-{
-    PROCESS_STATE_RUNNING = 0,           /*! process is executing                           */
-    PROCESS_STATE_STOPPED = 1,           /*! process has been stopped by a signal           */
-    PROCESS_STATE_KILLED  = 2,           /*! process has been killed by a signal            */
-    PROCESS_STATE_EXITED  = 3,           /*! process terminated with an exit                */ 
-};
+ * The termination state is a 32 bits word:
+ * - the 8 LSB bits contain the user defined exit status
+ * - the 24 other bits contain the flags defined below
+ ********************************************************************************************/
+
+#define PROCESS_FLAG_BLOCK 0x100  /*! process received as SIGSTOP signal                    */
+#define PROCESS_FLAG_KILL  0x200  /*! process terminated by a sys_kill()                    */
+#define PROCESS_FLAG_EXIT  0x400  /*! process terminated by a sys_exit()                    */ 
+#define PROCESS_FLAG_WAIT  0x800  /*! parent process executed successfully a sys_wait()     */
 
 /*********************************************************************************************
@@ -118,4 +117,5 @@
  * 6) The <local_list>, <copies_list>, <th_tbl>, <th_nr>, <th_lock> fields
  *    are defined in all process descriptors copies.
+ * 7) The termination <flags> and <exit_status> are only defined in the reference cluster.
  ********************************************************************************************/
 
@@ -155,5 +155,5 @@
     remote_spinlock_t sync_lock;        /*! lock protecting sem,mutex,barrier,condvar lists */
 
-    uint32_t          state;            /*! RUNNING / STOPPED / KILLED / EXITED             */
+    uint32_t          term_state;       /*! termination status (flags & exit status)        */
 
     bool_t            txt_owner;        /*! current TXT owner                               */
@@ -168,6 +168,4 @@
 typedef struct exec_info_s
 {
-    pid_t              pid;            /*! process identifier (both parent and child)       */
-
     char               path[CONFIG_VFS_MAX_PATH_LENGTH];   /*!  .elf file path              */
 
@@ -276,12 +274,4 @@
 
 /*********************************************************************************************
- * This function returns a printable string defining the process state.
- *********************************************************************************************
- * @ state   : RUNNING / BLOCKED / EXITED / KILLED
- * @ return a string pointer.
- ********************************************************************************************/
-char * process_state_str( uint32_t state );
-
-/*********************************************************************************************
  * This debug function diplays on the kernel terminal TXT0 detailed informations on a 
  * reference process identified by the <process_xp> argument.
@@ -324,6 +314,6 @@
 
 /*********************************************************************************************
- * This function blocks all threads (but the client thread defined by the <client_xp>
- * argument) for a given <process> in a given cluster.
+ * This function blocks all threads for a given <process> in a given cluster.
+ * The calling thread cannot be a target thread.
  * It loops on all local threads of the process, set the THREAD_BLOCKED_GLOBAL bit, 
  * and request the relevant schedulers to acknowledge the blocking, using IPI if required. 
@@ -332,8 +322,6 @@
  *********************************************************************************************
  * @ process     : pointer on the target process descriptor.
- * @ client_xp   : extended pointer on the client thread, that should not be blocked.
- ********************************************************************************************/
-void process_block_threads( process_t * process,
-                            xptr_t      client_xp );
+ ********************************************************************************************/
+void process_block_threads( process_t * process );
 
 /*********************************************************************************************
@@ -345,6 +333,8 @@
 
 /*********************************************************************************************
- * This function delete all threads, (but the client thread defined by the <client_xp>
- * argument) for a given <process> in a given cluster.
+ * This function marks for deletion all threads - but one _ for a given <process>
+ * in a given cluster. The main thread in owner cluster is NOT marked.
+ * It will be marked for deletion by the parent process sys_wait().
+ * The calling thread cannot be a target thread.
  * It loops on all local threads of the process, and set the THREAD_FLAG_REQ_DELETE bit.
  * For each marked thread, the following actions will be done by the scheduler at the next
@@ -357,8 +347,6 @@
  *********************************************************************************************
  * @ process     : pointer on the process descriptor.
- * @ client_xp   : extended pointer on the client thread, that should not be deleted.
- ********************************************************************************************/
-void process_delete_threads( process_t * process,
-                             xptr_t      client_xp );
+ ********************************************************************************************/
+void process_delete_threads( process_t * process );
 
 /*********************************************************************************************
@@ -396,5 +384,5 @@
  * associated "child" thread descriptor in the local cluster. This function can involve
  * up to three different clusters :
- * - the local (child) cluster can be any cluster defined by the sys_fork function.
+ * - the child (local) cluster can be any cluster defined by the sys_fork function.
  * - the parent cluster must be the reference cluster for the parent process.
  * - the client cluster containing the thread requesting the fork can be any cluster.
@@ -416,28 +404,19 @@
 
 /*********************************************************************************************
- * This function implement the "exit" system call, and is called by the sys_exit() function.
- * It must be executed by a thread running in the calling process owner cluster.
- * It uses twice the multicast RPC_PROCESS_SIGNAL to first block all process threads
- * in all clusters, and then delete all threads and process descriptors.
- *********************************************************************************************
- * @ pid      : process identifier.
- * @ status   : exit return value.
- ********************************************************************************************/
-void process_make_exit( pid_t       pid,
-                        uint32_t    status );
-
-/*********************************************************************************************
- * This function implement the "kill" system call, and is called by the sys_kill() function.
- * It must be executed by a thread running in the target process owner cluster.
- * Only the SIGKILL, SIGSTOP, and SIGCONT signals are supported.
- * User defined handlers are not supported.
- * It uses once or twice the multicast RPC_PROCESS_SIGNAL to block, unblock or delete
- * all process threads in all clusters, and then delete process descriptors.
- *********************************************************************************************
- * @ pid     : process identifier.
- * @ sig_id  : signal type.
- ********************************************************************************************/
-void process_make_kill( pid_t     pid,
-                        uint32_t  sig_id );
+ * This function is called by both the sys_kill() and sys_exit() system calls.
+ * It must be executed by an RPC thread running in the target process owner cluster.
+ * It uses twice the process_sigaction() function: 
+ * - first, to block all target process threads, in all clusters.
+ * - second, to delete all target process threads in all clusters.
+ * Finally, it synchronizes with the parent process sys_wait() function that MUST be called
+ * by the parent process main thread.
+ *********************************************************************************************
+ * @ process      : pointer on process descriptor in owner cluster.
+ * @ is_exit      : true when called by sys_exit() / false when called by sys_kill().
+ * @ exit_status  : exit status, when called by sys_exit().
+ ********************************************************************************************/
+void process_make_kill( process_t * process,
+                        bool_t      is_exit,
+                        uint32_t    exit_status );
 
 
