Changeset 436 for trunk/user
- Timestamp:
- Mar 7, 2018, 9:02:03 AM (7 years ago)
- Location:
- trunk/user
- Files:
-
- 4 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 -
trunk/user/ksh/ksh.c
r435 r436 13 13 14 14 #define CMD_MAX_SIZE (256) // max number of characters in one command 15 #define LOG_DEPTH ( 256)// max number of registered commands15 #define LOG_DEPTH (32) // max number of registered commands 16 16 #define MAX_ARGS (32) // max number of arguments in a command 17 17 #define FIFO_SIZE (1024) // FIFO depth for recursive ls … … 228 228 } // end cmd_cp() 229 229 230 ///////////////////////////////////////////////// 231 static void cmd_display( int argc , char **argv ) 232 { 233 unsigned int cxy; 234 unsigned int lid; 235 unsigned int pid; 236 unsigned int txt_id; 237 238 if( strcmp( argv[1] , "vmm" ) == 0 ) 239 { 240 if( argc != 3 ) 241 { 242 printf(" usage: display vmm pid\n"); 243 return; 244 } 245 246 pid = atoi(argv[2]); 247 248 if( display_vmm( pid ) ) 249 { 250 printf(" error: illegal arguments pid = %x\n", pid ); 251 } 252 } 253 else if( strcmp( argv[1] , "sched" ) == 0 ) 254 { 255 if( argc != 4 ) 256 { 257 printf(" usage: display sched cxy lid\n"); 258 return; 259 } 260 261 cxy = atoi(argv[2]); 262 lid = atoi(argv[3]); 263 264 if( display_sched( cxy , lid ) ) 265 { 266 printf(" error: illegal arguments cxy = %x / lid = %d\n", cxy, lid ); 267 } 268 } 269 else if( strcmp( argv[1] , "process" ) == 0 ) 270 { 271 if( argc != 3 ) 272 { 273 printf(" usage: display process cxy\n"); 274 return; 275 } 276 277 cxy = atoi(argv[2]); 278 279 if( display_cluster_processes( cxy ) ) 280 { 281 printf(" error: illegal argument cxy = %x\n", cxy ); 282 } 283 } 284 else if( strcmp( argv[1] , "txt" ) == 0 ) 285 { 286 if( argc != 3 ) 287 { 288 printf(" usage: display txt txt_id\n"); 289 return; 290 } 291 292 txt_id = atoi(argv[2]); 293 294 if( display_txt_processes( txt_id ) ) 295 { 296 printf(" error: illegal argument txt_id = %x\n", txt_id ); 297 } 298 } 299 else if( strcmp( argv[1] , "vfs" ) == 0 ) 300 { 301 if( argc != 2 ) 302 { 303 printf(" usage: display vfs\n"); 304 return; 305 } 306 307 display_vfs(); 308 } 309 else if( strcmp( argv[1] , "chdev" ) == 0 ) 310 { 311 if( argc != 2 ) 312 { 313 printf(" usage: display chdev\n"); 314 return; 315 } 316 317 display_chdev(); 318 } 319 else 320 { 321 printf(" usage: display (vmm/sched/process/vfs/chdev/txt) [arg2] [arg3]\n"); 322 } 323 } // end cmd_display() 324 230 325 ///////////////////////////////////////// 231 326 static void cmd_fg(int argc, char **argv) … … 250 345 printf(" error: cannot find process %x\n", pid ); 251 346 } 252 } 347 } // end cmd_fg() 253 348 254 349 ////////////////////////////////////////////// … … 297 392 static void cmd_load( int argc , char **argv ) 298 393 { 299 int ret; 300 unsigned int ksh_pid; 301 char * pathname; 302 unsigned int background; 394 int ret_fork; // return value from fork 395 int ret_exec; // return value from exec 396 unsigned int ksh_pid; // KSH process PID 397 unsigned int new_pid; // new process PID 398 unsigned int rcv_pid; // terminating process PID 399 char * pathname; // path to .elf file 400 unsigned int background; // background execution if non zero 401 int status; // new process exit status 303 402 304 403 if( (argc < 2) || (argc > 3) ) … … 317 416 318 417 // KSH process fork CHILD process 319 ret = fork();320 321 if ( ret < 0 ) // it is a failure reported to parent418 ret_fork = fork(); 419 420 if ( ret_fork < 0 ) // it is a failure reported to KSH 322 421 { 323 422 printf(" error: ksh process unable to fork\n"); 324 423 } 325 else if (ret == 0)// it is the CHILD process326 { 327 // give back to KSH process the terminal ownership424 else if (ret_fork == 0) // it is the CHILD process 425 { 426 // give back to KSH terminal ownership if required 328 427 if( background ) fg( ksh_pid ); 329 428 330 429 // CHILD process exec NEW process 331 ret = exec( pathname , NULL , NULL );332 333 if( ret )430 ret_exec = exec( pathname , NULL , NULL ); 431 432 if( ret_exec ) 334 433 { 335 434 printf(" error: new process unable to exec <%s>\n", pathname ); 336 435 exit(0); 436 } 437 } 438 else // it is the parent KSH : ret_fork is the new process PID 439 { 440 new_pid = ret_fork; 441 442 // wait new process completion 443 rcv_pid = wait( &status ); 444 445 if( rcv_pid == new_pid ) 446 { 447 printf("\n\n exit %s / status = %x\n\n", pathname, (status &0xFF) ); 337 448 } 338 } 449 else 450 { 451 printf("\n\n abnormal termination for %s \n\n", pathname ); 452 } 453 } 454 339 455 } // end cmd_load 340 456 … … 347 463 for (i = 0; i < LOG_DEPTH; i++) 348 464 { 349 printf(" - % zu\t: %s\n", i, &log_entries[i].buf);465 printf(" - %d\t: %s\n", i, &log_entries[i].buf); 350 466 } 351 467 } … … 476 592 { 477 593 cmd_rm(argc, argv); 478 }479 480 /////////////////////////////////////////////////481 static void cmd_display( int argc , char **argv )482 {483 unsigned int cxy;484 unsigned int lid;485 unsigned int pid;486 unsigned int txt_id;487 488 if( strcmp( argv[1] , "vmm" ) == 0 )489 {490 if( argc != 3 )491 {492 printf(" usage: display vmm pid\n");493 return;494 }495 496 pid = atoi(argv[2]);497 498 if( display_vmm( pid ) )499 {500 printf(" error: illegal arguments pid = %x\n", pid );501 }502 }503 else if( strcmp( argv[1] , "sched" ) == 0 )504 {505 if( argc != 4 )506 {507 printf(" usage: display sched cxy lid\n");508 return;509 }510 511 cxy = atoi(argv[2]);512 lid = atoi(argv[3]);513 514 if( display_sched( cxy , lid ) )515 {516 printf(" error: illegal arguments cxy = %x / lid = %d\n", cxy, lid );517 }518 }519 else if( strcmp( argv[1] , "process" ) == 0 )520 {521 if( argc != 3 )522 {523 printf(" usage: display process cxy\n");524 return;525 }526 527 cxy = atoi(argv[2]);528 529 if( display_cluster_processes( cxy ) )530 {531 printf(" error: illegal argument cxy = %x\n", cxy );532 }533 }534 else if( strcmp( argv[1] , "txt" ) == 0 )535 {536 if( argc != 3 )537 {538 printf(" usage: display txt txt_id\n");539 return;540 }541 542 txt_id = atoi(argv[2]);543 544 if( display_txt_processes( txt_id ) )545 {546 printf(" error: illegal argument txt_id = %x\n", txt_id );547 }548 }549 else if( strcmp( argv[1] , "vfs" ) == 0 )550 {551 if( argc != 2 )552 {553 printf(" usage: display vfs\n");554 return;555 }556 557 display_vfs();558 }559 else if( strcmp( argv[1] , "chdev" ) == 0 )560 {561 if( argc != 2 )562 {563 printf(" usage: display chdev\n");564 return;565 }566 567 display_chdev();568 }569 else570 {571 printf(" usage: display (vmm/sched/process/vfs/chdev/txt) [arg2] [arg3]\n");572 }573 594 } 574 595 … … 687 708 // - ESCAPE : the character (ESC) has been found 688 709 // - BRAKET : the wo characters (ESC,[) have been found 710 689 711 unsigned int state = NORMAL; 690 691 712 692 713 // @@@ … … 694 715 // @@@ 695 716 717 char string[64]; 696 718 697 719 while (1) … … 738 760 { 739 761 } 740 else if (c == 0x1B) // ESC => start an escape sequence762 else if (c == (char)0x1B) // ESC => start an escape sequence 741 763 { 742 764 state = ESCAPE; … … 838 860 } 839 861 } 840 } 841 862 } // end main() 863 -
trunk/user/pgcd/pgcd.c
r434 r436 9 9 10 10 #include <stdlib.h> 11 #include <stdio.h> 11 12 12 13 … … 14 15 void main() 15 16 { 16 int opx; 17 int opy; 17 int opx; 18 int opy; 19 unsigned long long cycle; 18 20 19 printf( "*** Starting interactive pgcd ***\n\n" ); 21 get_cycle( &cycle ); 22 printf( "\n[PGCD] starts / cycle %d\n", (unsigned int)cycle ); 20 23 21 24 while (1) -
trunk/user/sort/sort.c
r435 r436 265 265 266 266 get_cycle( &cycle ); 267 printf("\n[SORT] completes barrier init at cycle %d continue ?\n", (unsigned int)cycle ); 268 getchar(); 267 printf("\n[SORT] completes barrier init at cycle %d\n", (unsigned int)cycle ); 269 268 270 269 // Array to sort initialization … … 356 355 { 357 356 printf("\n[SORT] failure at cycle %d\n", (unsigned int)cycle ); 358 exit( 0);357 exit( 1 ); 359 358 } 360 359
Note: See TracChangeset
for help on using the changeset viewer.