Changeset 427 for trunk/user/ksh
- Timestamp:
- Jan 29, 2018, 6:06:11 PM (7 years ago)
- Location:
- trunk/user/ksh
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/user/ksh/Makefile
r407 r427 21 21 $(LIBS)/build/stdlib.o \ 22 22 $(LIBS)/build/stdio.o \ 23 $(LIBS)/build/nostdio.o \24 23 $(LIBS)/build/string.o \ 25 24 $(LIBS)/build/malloc.o \ … … 50 49 $(DU) -D $@ > $@.txt 51 50 52 $(LIBS)/build/nostdio.o : $(LIBS)/nostdio.c $(LIBS)/nostdio.h53 $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $<54 $(DU) -D $@ > $@.txt55 56 51 $(LIBS)/build/string.o : $(LIBS)/string.c $(LIBS)/string.h 57 52 $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $< -
trunk/user/ksh/ksh.c
r418 r427 7 7 /////////////////////////////////////////////////////////////////////////////// 8 8 9 #include <nostdio.h>10 9 #include <stdio.h> 11 10 #include <stdlib.h> … … 229 228 } // end cmd_cp() 230 229 230 ///////////////////////////////////////// 231 static void cmd_fg(int argc, char **argv) 232 { 233 unsigned int pid; 234 235 if (argc != 2) 236 { 237 printf(" usage: %s pid\n", argv[0]); 238 return; 239 } 240 241 pid = atoi( argv[1] ); 242 243 if( pid == 0 ) 244 { 245 printf(" error: ilegal pid format\n" ); 246 } 247 248 if( fg( pid ) ) 249 { 250 printf(" error: cannot find process %x\n", pid ); 251 } 252 } 253 231 254 ////////////////////////////////////////////// 232 255 static void cmd_help( int argc , char **argv ) … … 258 281 } 259 282 260 pid = atoi(argv[1]); 283 pid = atoi( argv[1] ); 284 285 if( pid == 0 ) 286 { 287 printf(" error: ilegal pid format\n" ); 288 } 261 289 262 290 if( kill( pid , SIGKILL ) ) … … 264 292 printf(" error: unable to kill process %x\n", pid ); 265 293 } 266 267 printf("\n ... done\n" );268 269 294 } // end cmd_kill() 270 295 … … 272 297 static void cmd_load( int argc , char **argv ) 273 298 { 274 unsigned int pid;275 unsigned int error;299 unsigned int ret_pid; 300 unsigned int new_pid; 276 301 char * pathname; 277 278 if (argc != 2) 279 { 280 printf(" usage: %s pathname \n", argv[0] ); 302 unsigned int background; 303 304 if( (argc < 2) || (argc > 3) ) 305 { 306 printf(" usage: %s pathname [&] \n", argv[0] ); 281 307 return; 282 308 } … … 284 310 pathname = argv[1]; 285 311 312 if( argc == 3 ) background = (argv[2][0] == '&'); 313 286 314 // fork system call 287 pid = fork();288 289 if ( pid == 0) // it is the child process315 ret_pid = fork(); 316 317 if (ret_pid == 0) // it is the child process 290 318 { 291 319 // exec system call 292 error = exec( pathname , NULL , NULL ); 293 294 if( error ) 320 if( exec( pathname , NULL , NULL ) ) 295 321 { 296 322 printf(" error: new process unable to exec <%s>\n", pathname ); 297 323 exit(0); 298 324 } 325 326 // get new process pid 327 new_pid = getpid(); 328 329 // give new process terminal ownership 330 if( background == 0 ) fg( new_pid ); 299 331 } 300 else if ( pid < 0 ) // it is a failure reported to parent332 else if ( ret_pid < 0 ) // it is a failure reported to parent 301 333 { 302 334 printf(" error: unable to fork\n"); … … 443 475 } 444 476 445 /////////////////////////////////////////////// 446 static void cmd_sched( int argc , char **argv ) 447 { 448 unsigned int cxy; 449 unsigned int lid; 450 451 if (argc != 3) 452 { 453 printf(" usage: sched cxy lid\n"); 454 return; 455 } 456 457 cxy = atoi(argv[1]); 458 lid = atoi(argv[2]); 459 460 if( get_sched( cxy , lid ) ) 461 { 462 printf(" error: illegal arguments\n"); 477 ///////////////////////////////////////////////// 478 static void cmd_display( int argc , char **argv ) 479 { 480 unsigned int cxy; 481 unsigned int lid; 482 unsigned int pid; 483 484 if( strcmp( argv[1] , "vmm" ) == 0 ) 485 { 486 if( argc != 3 ) 487 { 488 printf(" usage: display vmm pid\n"); 489 return; 490 } 491 492 pid = atoi(argv[2]); 493 494 if( display_vmm( pid ) ) 495 { 496 printf(" error: illegal arguments pid = %x\n", pid ); 497 } 498 } 499 else if( strcmp( argv[1] , "sched" ) == 0 ) 500 { 501 if( argc != 4 ) 502 { 503 printf(" usage: display sched cxy lid\n"); 504 return; 505 } 506 507 cxy = atoi(argv[2]); 508 lid = atoi(argv[3]); 509 510 if( display_sched( cxy , lid ) ) 511 { 512 printf(" error: illegal arguments cxy = %x / lid = %d\n", cxy, lid ); 513 } 514 } 515 else if( strcmp( argv[1] , "process" ) == 0 ) 516 { 517 if( argc != 3 ) 518 { 519 printf(" usage: display process cxy\n"); 520 return; 521 } 522 523 cxy = atoi(argv[2]); 524 525 if( display_process( cxy ) ) 526 { 527 printf(" error: illegal argument cxy = %x\n", cxy ); 528 } 529 } 530 else if( strcmp( argv[1] , "vfs" ) == 0 ) 531 { 532 if( argc != 2 ) 533 { 534 printf(" usage: display vfs\n"); 535 return; 536 } 537 538 display_vfs(); 539 } 540 else if( strcmp( argv[1] , "chdev" ) == 0 ) 541 { 542 if( argc != 2 ) 543 { 544 printf(" usage: display chdev\n"); 545 return; 546 } 547 548 display_chdev(); 549 } 550 else 551 { 552 printf(" usage display (vmm/sched/process/vfs/chdev) [cxy] [lid]\n"); 463 553 } 464 554 } … … 470 560 ksh_cmd_t cmd[] = 471 561 { 472 { "cat", "display file content", cmd_cat }, 473 { "cd", "change current directory", cmd_cd }, 474 { "cp", "replicate a file in file system", cmd_cp }, 475 { "load", "load an user application", cmd_load }, 476 { "help", "list available commands", cmd_help }, 477 { "kill", "kill an application (all threads)", cmd_kill }, 478 { "log", "list registered commands", cmd_log }, 479 { "ls", "list directory entries", cmd_ls }, 480 { "mkdir", "create a new directory", cmd_mkdir }, 481 { "mv", "move a file in file system", cmd_mv }, 482 { "pwd", "print current working directory", cmd_pwd }, 483 { "rm", "remove a file from file system", cmd_rm }, 484 { "rmdir", "remove a directory from file system", cmd_rmdir }, 485 { "sched", "display scheduler state", cmd_sched }, 486 { NULL, NULL, NULL } 562 { "cat", "display file content", cmd_cat }, 563 { "cd", "change current directory", cmd_cd }, 564 { "cp", "replicate a file in file system", cmd_cp }, 565 { "fg", "put a process in foreground", cmd_fg }, 566 { "display", "display vmm/sched/process/vfs/chdev", cmd_display }, 567 { "load", "load an user application", cmd_load }, 568 { "help", "list available commands", cmd_help }, 569 { "kill", "kill an application (all threads)", cmd_kill }, 570 { "log", "list registered commands", cmd_log }, 571 { "ls", "list directory entries", cmd_ls }, 572 { "mkdir", "create a new directory", cmd_mkdir }, 573 { "mv", "move a file in file system", cmd_mv }, 574 { "pwd", "print current working directory", cmd_pwd }, 575 { "rm", "remove a file from file system", cmd_rm }, 576 { "rmdir", "remove a directory from file system", cmd_rmdir }, 577 { NULL, NULL, NULL } 487 578 }; 488 579
Note: See TracChangeset
for help on using the changeset viewer.