Changeset 436 for trunk/user/ksh
- Timestamp:
- Mar 7, 2018, 9:02:03 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.