Changeset 434 for trunk/user/ksh
- Timestamp:
- Feb 14, 2018, 3:41:31 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/user/ksh/ksh.c
r427 r434 297 297 static void cmd_load( int argc , char **argv ) 298 298 { 299 unsigned int ret_pid;300 unsigned int new_pid;299 int ret; 300 unsigned int ksh_pid; 301 301 char * pathname; 302 302 unsigned int background; … … 304 304 if( (argc < 2) || (argc > 3) ) 305 305 { 306 printf(" usage: %s pathname [&] 306 printf(" usage: %s pathname [&]\n", argv[0] ); 307 307 return; 308 308 } … … 311 311 312 312 if( argc == 3 ) background = (argv[2][0] == '&'); 313 314 // fork system call 315 ret_pid = fork(); 316 317 if (ret_pid == 0) // it is the child process 318 { 319 // exec system call 320 if( exec( pathname , NULL , NULL ) ) 313 else background = 0; 314 315 // get KSH process PID 316 ksh_pid = getpid(); 317 318 // KSH process fork CHILD process 319 ret = fork(); 320 321 if ( ret < 0 ) // it is a failure reported to parent 322 { 323 printf(" error: ksh process unable to fork\n"); 324 } 325 else if (ret == 0) // it is the CHILD process 326 { 327 // give back to KSH process the terminal ownership 328 if( background ) fg( ksh_pid ); 329 330 // CHILD process exec NEW process 331 ret = exec( pathname , NULL , NULL ); 332 333 if( ret ) 321 334 { 322 335 printf(" error: new process unable to exec <%s>\n", pathname ); 323 336 exit(0); 324 337 } 325 326 // get new process pid327 new_pid = getpid();328 329 // give new process terminal ownership330 if( background == 0 ) fg( new_pid );331 338 } 332 else if ( ret_pid < 0 ) // it is a failure reported to parent333 {334 printf(" error: unable to fork\n");335 }336 339 } // end cmd_load 337 340 … … 624 627 if (!found) 625 628 { 626 printf(" \n undefined command %s\n", argv[0]);629 printf(" undefined command <%s>\n", argv[0]); 627 630 } 628 631 }
Note: See TracChangeset
for help on using the changeset viewer.