Changeset 436 for trunk/user/init
- Timestamp:
- Mar 7, 2018, 9:02:03 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/user/init/init.c
r435 r436 20 20 #include <pthread.h> 21 21 22 #define DELAY_BETWEEN_FORK 10000023 24 22 ////////// 25 23 int main() … … 28 26 int ret_fork; // fork return value 29 27 int ret_exec; // fork return value 30 int r eceived_pid;// pid received from the wait syscall28 int rcv_pid; // pid received from the wait syscall 31 29 int status; // used by the wait syscall 32 30 char string[64]; … … 41 39 ret_fork = fork(); 42 40 43 if( ret_fork < 0 ) // error in fork41 if( ret_fork < 0 ) // error in fork 44 42 { 45 43 // INIT display error message on TXT0 terminal 46 snprintf( string , 64 , 47 "INIT cannot fork child[%d]\n" , i ); 44 snprintf( string , 64 , "INIT cannot fork child[%d]" , i ); 48 45 display_string( string ); 49 46 50 // INIT exit47 // INIT suicide 51 48 exit( 0 ); 52 49 } … … 58 55 if ( ret_exec ) // error in exec 59 56 { 60 // display error message on TXT0 terminal57 // CHILD[i] display error message on TXT0 terminal 61 58 snprintf( string , 64 , 62 "CHILD[%d] cannot exec KSH[%d] / ret_exec = %d \n" , i , i , ret_exec );59 "CHILD[%d] cannot exec KSH[%d] / ret_exec = %d" , i , i , ret_exec ); 63 60 display_string( string ); 64 61 } … … 67 64 { 68 65 // INIT display CHILD[i] process PID 69 snprintf( string , 64 , 70 "INIT forked CHILD[%d] / pid = %x\n", i , ret_fork ); 66 snprintf( string , 64 , "INIT created KSH[%d] / pid = %x", i , ret_fork ); 71 67 display_string( string ); 72 68 } 73 74 69 } 75 70 76 71 // This loop detects the termination of the KSH[i] processes, 77 // to recreate theseprocess when required.72 // and recreate a new KSH[i] process when required. 78 73 while( 1 ) 79 74 { 80 75 // block on child processes termination 81 r eceived_pid = wait( &status );76 rcv_pid = wait( &status ); 82 77 83 78 if( WIFSTOPPED( status ) ) // stopped => unblock it 84 79 { 85 80 // display string to report unexpected KSH process block 86 snprintf( string , 64 , "KSH process %x unexpectedly stopped" , received_pid );81 snprintf( string , 64 , "KSH process %x stopped => unblock it" , rcv_pid ); 87 82 display_string( string ); 88 83 89 } 84 // TODO : unblock KSH 85 86 } // end KSH stopped handling 90 87 91 88 if( WIFSIGNALED( status ) || WIFEXITED( status ) ) // killed => recreate it 92 89 { 93 90 // display string to report unexpected KSH process termination 94 snprintf( string , 64 , "KSH process %x unexpectedly terminated" , received_pid );91 snprintf( string , 64 , "KSH process %x terminated => recreate KSH", rcv_pid ); 95 92 display_string( string ); 96 } 93 94 // INIT process fork a new CHILD process 95 ret_fork = fork(); 96 97 if( ret_fork < 0 ) // error in fork 98 { 99 // INIT display error message on TXT0 terminal 100 snprintf( string , 64 , "INIT cannot fork child"); 101 display_string( string ); 102 103 // INIT suicide 104 exit( 0 ); 105 } 106 else if( ret_fork == 0 ) // we are in CHILD process 107 { 108 // CHILD process exec process KSH 109 ret_exec = exec( "/bin/user/ksh.elf" , NULL , NULL ); 110 111 if ( ret_exec ) // error in exec 112 { 113 // CHILD display error message on TXT0 terminal 114 snprintf( string , 64 , "CHILD cannot exec KSH" ); 115 display_string( string ); 116 } 117 } 118 else // we are in INIT process 119 { 120 // INIT display new CHILD process PID 121 snprintf( string , 64 , "INIT forked CHILD / pid = %x", ret_fork ); 122 display_string( string ); 123 } 124 } // end KSH kill handling 97 125 } 98 126
Note: See TracChangeset
for help on using the changeset viewer.