Changeset 434 for trunk/user/ksh/ksh.c


Ignore:
Timestamp:
Feb 14, 2018, 3:41:31 PM (6 years ago)
Author:
alain
Message:

blap

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/user/ksh/ksh.c

    r427 r434  
    297297static void cmd_load( int argc , char **argv )
    298298{
    299         unsigned int         ret_pid;
    300     unsigned int         new_pid;
     299        int                  ret;
     300    unsigned int         ksh_pid;
    301301        char               * pathname;
    302302    unsigned int         background;
     
    304304        if( (argc < 2) || (argc > 3) ) 
    305305    {
    306                 printf("  usage: %s pathname [&] \n", argv[0] );
     306                printf("  usage: %s pathname [&]\n", argv[0] );
    307307                return;
    308308        }
     
    311311
    312312    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 )
    321334        {
    322335            printf("  error: new process unable to exec <%s>\n", pathname );
    323336            exit(0);
    324337        }
    325 
    326         // get new process pid
    327         new_pid = getpid();
    328 
    329         // give new process terminal ownership
    330         if( background == 0 ) fg( new_pid );
    331338        }
    332     else if ( ret_pid < 0 )  // it is a failure reported to parent
    333     {
    334         printf("  error: unable to fork\n");
    335     }
    336339}   // end cmd_load
    337340
     
    624627                if (!found)
    625628        {
    626                         printf("\n  undefined command %s\n", argv[0]);
     629                        printf("  undefined command <%s>\n", argv[0]);
    627630                }
    628631        }
Note: See TracChangeset for help on using the changeset viewer.