Index: trunk/kernel/kern/process.h
===================================================================
--- trunk/kernel/kern/process.h	(revision 416)
+++ trunk/kernel/kern/process.h	(revision 428)
@@ -54,5 +54,5 @@
 
 /*********************************************************************************************
- * This enum defines the actions that can be executed by the process_signal() function.
+ * This enum defines the actions that can be executed by the process_sigaction() function.
  ********************************************************************************************/
 
@@ -62,4 +62,16 @@
     UNBLOCK_ALL_THREADS  = 22,
     DELETE_ALL_THREADS   = 33, 
+};
+
+/*********************************************************************************************
+ * 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                */ 
 };
 
@@ -102,7 +114,7 @@
  * 4) The <sem_root>, <mutex_root>, <barrier_root>, <condvar_root>, and the associated
  *    <sync_lock>, that are dynamically allocated, are only defined in the reference cluster.
- * 5) The <children_root>, and <children_nr> fields are only defined in the reference
- *    cluster, and are undefined in other clusters.
- * 6) The <brothers_list>, <local_list>, <copies_list>, <th_tbl>, <th_nr>, <th_lock> fields
+ * 5) The <children_root>, <children_nr>, <brothers_list>, and <txt_list> fields are only
+ *    defined in the reference cluster, and are undefined in other clusters.
+ * 6) The <local_list>, <copies_list>, <th_tbl>, <th_nr>, <th_lock> fields
  *    are defined in all process descriptors copies.
  ********************************************************************************************/
@@ -115,8 +127,8 @@
 
 	xptr_t            vfs_root_xp;      /*! extended pointer on current VFS root inode      */
-	xptr_t            vfs_bin_xp;       /*! extended pointer on .elf file inode             */
+	xptr_t            vfs_bin_xp;       /*! extended pointer on .elf file descriptor        */
 	pid_t             pid;              /*! process identifier                              */
-	pid_t             ppid;             /*! parent process identifier                       */
     xptr_t            ref_xp;           /*! extended pointer on reference process           */
+    xptr_t            parent_xp;        /*! extended pointer on parent process              */
 
 	xptr_t            vfs_cwd_xp;       /*! extended pointer on current working dir inode   */
@@ -124,12 +136,15 @@
 
 	xlist_entry_t     children_root;    /*! root of the children process xlist              */
+    remote_spinlock_t children_lock;    /*! lock protecting children process xlist          */
     uint32_t          children_nr;      /*! number of children processes                    */
 
-	xlist_entry_t     brothers_list;    /*! member of list of children of same parent       */
+	xlist_entry_t     children_list;    /*! member of list of children of same parent       */
     xlist_entry_t     local_list;       /*! member of list of process in same cluster       */
     xlist_entry_t     copies_list;      /*! member of list of copies of same process        */
+    xlist_entry_t     txt_list;         /*! member of list of processes sharing same TXT    */
 
 	spinlock_t        th_lock;          /*! lock protecting th_tbl[] concurrent access      */
 	uint32_t          th_nr;            /*! number of threads in this cluster               */
+
 	struct thread_s * th_tbl[CONFIG_THREAD_MAX_PER_CLUSTER]; /*! pointers on local threads  */
 
@@ -138,6 +153,9 @@
     xlist_entry_t     barrier_root;     /*! root of the process barrier list                */
     xlist_entry_t     condvar_root;     /*! root of the process condvar list                */
-
     remote_spinlock_t sync_lock;        /*! lock protecting sem,mutex,barrier,condvar lists */
+
+    uint32_t          state;            /*! RUNNING / STOPPED / KILLED / EXITED             */
+
+    bool_t            txt_owner;        /*! current TXT owner                               */
 }
 process_t;
@@ -182,40 +200,39 @@
 
 /*********************************************************************************************
+ * This function initialize, in each cluster, the kernel "process_zero", that is the owner
+ * of all kernel threads in a given cluster. It is called by the kernel_init() function.
+ * The process_zero descriptor is allocated as a global variable in file kernel_init.c 
+ * Both the PID and PPID fields are set to zero, the ref_xp is the local process_zero,
+ * and the parent process is set to XPTR_NULL. The th_tbl[] is initialized as empty.
+ *********************************************************************************************
+ * @ process      : [in] pointer on local process descriptor to initialize.
+ ********************************************************************************************/
+void process_zero_create( process_t * process );
+
+/*********************************************************************************************
  * This function allocates memory and initializes the "process_init" descriptor and the
  * associated "thread_init" descriptor. It is called once at the end of the kernel 
- * initialisation procedure, by the kernel process in cluster_IO.
+ * initialisation procedure. Its local process identifier is 1, and parent process 
+ * is the kernel process in cluster 0.
  * The "process_init" is the first user process, and all other user processes will be forked
  * from this process. The code executed by "process_init" is stored in a .elf file, whose
  * pathname is defined by the CONFIG_PROCESS_INIT_PATH configuration variable. 
- * The process_init streams are defined  by the CONFIG_INIT_[STDIN/STDOUT/STDERR] variables.
- * Its local process identifier is 1, and parent process is the local kernel process_zero.
+ * The process_init does not use the [STDIN/STDOUT/STDERR] streams, but it is linked
+ * to kernel TXT0, because these streams must be defined for all user processes.
  ********************************************************************************************/
 void process_init_create();
 
 /*********************************************************************************************
- * This function initialize, in each cluster, the kernel "process_zero", that is the owner
- * of all kernel threads in a given cluster. It is called by the kernel_init() function.
- * Both the PID and PPID fields are set to zero, and the ref_xp is the local process_zero.
- * The th_tbl[] is initialized as empty.
- *********************************************************************************************
- * @ process      : [in] pointer on local process descriptor to initialize.
- ********************************************************************************************/
-void process_zero_init( process_t * process );
-
-/*********************************************************************************************
- * This function initializes a local, reference user process descriptor from another process
- * descriptor, defined by the <model_xp> argument. The <process> descriptor, the <pid>, and
- * the <ppid> arguments must be previously defined by the caller.
- * It can be called by two functions, depending on the process type:
- * 1) if "process" is the "process_init", the parent is the kernel process. It is
- *    called once, by the process_init_create() function in cluster[xmax-1][ymax-1].
- * 2) if the caller is the process_make_fork() function, the model is generally a remote
- *    process, that is also the parent process.
-
- * 3) if the caller is the process_make_exec() function, the model is always a local process,
- *    and the parent is the parent of the model process. DEPRECATED [AG]
-
- * The following fields are initialised (for all process but process_zero).
- * - It set the pid / ppid / ref_xp fields.
+ * This function initializes a local, reference, user process descriptor from another process
+ * descriptor, defined by the <model_xp> argument. The <process> and <pid> arguments must
+ * be previously allocated by he caller. This function can be called by three functions:
+ * 1) process_init_create() : process is the reference INIT process / pid = 1 /
+ *    the parent and model process descriptors are both the kernel process_zero.
+ * 2) process_make_fork() : the model process descriptor is the (generally remote)
+ *    parent process.
+ * 3) process_make exec() : the model process is the local old_process, the new_process
+ *    parent is the same as the old_process parent. 
+ * The following fields are initialised :
+ * - It set the pid / ppid / ref_xp / parent_xp / state fields.
  * - It initializes the VMM (register the kentry, args, envs vsegs in VSL)
  * - It initializes the FDT, defining the three pseudo files STDIN / STDOUT / STDERR.
@@ -230,10 +247,10 @@
  * @ process      : [in] pointer on local process descriptor to initialize.
  * @ pid          : [in] process identifier.
- * @ ppid         : [in] parent process identifier.
- * @ model_xp     : [in] extended pointer on model process descriptor (local or remote).
+ * @ parent_xp    : [in] extended pointer on parent process descriptor.
+ * @ model_xp     : [in] extended pointer on model process descriptor.
  ********************************************************************************************/
 void process_reference_init( process_t * process,
                              pid_t       pid,
-                             pid_t       ppid,
+                             xptr_t      parent_xp,
                              xptr_t      model_xp );
 
@@ -259,10 +276,27 @@
 
 /*********************************************************************************************
- * This function returns a printable string defining the action for process_signa().
- *********************************************************************************************
- * @ action_type   : BLOCK_ALL_THREADS / UNBLOCK_ALL_THREADS / DELETE_ALL_THREADS
+ * This function returns a printable string defining the process state.
+ *********************************************************************************************
+ * @ state   : RUNNING / BLOCKED / EXITED / KILLED
  * @ return a string pointer.
  ********************************************************************************************/
-char * process_action_str( uint32_t action_type );
+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.
+ * It can be called by a thread running in any cluster.
+ *********************************************************************************************
+ * @ process_xp : extended pointer on reference process.
+ ********************************************************************************************/
+void process_display( xptr_t process_xp );
+
+/*********************************************************************************************
+ * This function returns a printable string defining the sigaction type.
+ *********************************************************************************************
+ * @ sigaction_type   : BLOCK_ALL_THREADS / UNBLOCK_ALL_THREADS / DELETE_ALL_THREADS
+ * @ return a string pointer.
+ ********************************************************************************************/
+char * process_action_str( uint32_t sigaction_type );
 
 /*********************************************************************************************
@@ -290,16 +324,16 @@
 
 /*********************************************************************************************
- * This function blocks all threads of a given user process in a given cluster.
+ * This function blocks all threads (but the client thread defined by the <client_xp>
+ * argument) for a given <process> in a given cluster.
  * 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. 
  * The threads are not detached from the scheduler, and not detached from the local process.
  * This function returns only when all blockable threads in cluster are actually blocked.
- * WARNING : the client thread defined by the <client_xp> argument is NOT blocked.
  *********************************************************************************************
  * @ process     : pointer on the target process descriptor.
  * @ client_xp   : extended pointer on the client thread, that should not be blocked.
  ********************************************************************************************/
-void process_block( process_t * process,
-                    xptr_t      client_xp );
+void process_block_threads( process_t * process,
+                            xptr_t      client_xp );
 
 /*********************************************************************************************
@@ -308,8 +342,9 @@
  * @ process     : pointer on the process descriptor.
  ********************************************************************************************/
-void process_unblock( process_t * process );
-
-/*********************************************************************************************
- * This function delete all threads, of a given user process in a given cluster.
+void process_unblock_threads( process_t * process );
+
+/*********************************************************************************************
+ * This function delete all threads, (but the client thread defined by the <client_xp>
+ * argument) for a given <process> in a given cluster.
  * 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
@@ -320,11 +355,10 @@
  * - the memory allocated to the thread descriptor is released.
  * - the memory allocated to the process descriptor is released, if it is the last thread.
- * WARNING : the client thread defined by the <client_xp> argument is NOT deleted.
  *********************************************************************************************
  * @ process     : pointer on the process descriptor.
  * @ client_xp   : extended pointer on the client thread, that should not be deleted.
  ********************************************************************************************/
-void process_delete( process_t * process,
-                     xptr_t      client_xp );
+void process_delete_threads( process_t * process,
+                             xptr_t      client_xp );
 
 /*********************************************************************************************
@@ -509,4 +543,54 @@
 
 
+/***************   Terminals related operations  ********************************************/
+
+/*********************************************************************************************
+ * This function scan the set of user TXT terminals to find a free terminal
+ * (the list of attached processes is empty for a free TXT terminal).
+ * It is called only by the process_reference_init() function when creating a KSH process.
+ * It makes a kernel panic if no free TXT terminal is found.
+ * As a KSH process is never deleted, the allocated TXT terminal is never released.
+ *********************************************************************************************
+ * @ return TXT terminal index if succes / kernel panic if no terminal found.
+ ********************************************************************************************/
+uint32_t process_txt_alloc();
+
+/*********************************************************************************************
+ * This function attach a reference process descriptor, identified by the <process>
+ * argument to a TXT terminal, identified by its <txt_id> channel index argument.
+ * It insert the process descriptor in the xlist rooted in the TXT_RX device.
+ * It is called by the process_reference_init() function.
+ *********************************************************************************************
+ * @ process  : local pointer on process descriptor.
+ * @ txt_id   : TXT channel index.
+ ********************************************************************************************/
+void process_txt_attach( process_t * process,
+                         uint32_t    txt_id );
+
+/*********************************************************************************************
+ * This function detach a reference process descriptor, identified by the <process_xp>
+ * argument, from the list of process attached to a given TXT terminal.
+ * It is called when the process is killed.
+ *********************************************************************************************
+ * @ process  : local pointer on process descriptor.
+ ********************************************************************************************/
+void process_txt_detach( process_t * process );                     
+
+/*********************************************************************************************
+ * This function gives to a process identified by the <process_xp> argument, and attached
+ * to terminal TXT[i] the exclusive ownership of the TXT_RX[i] terminal.
+ *********************************************************************************************
+ * @ process_xp  : extended pointer on reference process descriptor.
+ ********************************************************************************************/
+void process_txt_set_ownership( xptr_t process_xp );
+
+/*********************************************************************************************
+ * When the process identified by the <process_xp> argument has the exclusive ownership
+ * of the TXT_RX[i] terminal, this function gives this ownership to the KSH[i] process.
+ * It does nothing if the process is not the owner.
+ *********************************************************************************************
+ * @ process_xp  : extended pointer on reference process descriptor.
+ ********************************************************************************************/
+void process_txt_reset_ownership( xptr_t process_xp );
 
 #endif	/* _PROCESS_H_ */
