Changeset 427


Ignore:
Timestamp:
Jan 29, 2018, 6:06:11 PM (6 years ago)
Author:
alain
Message:

Several processes KSH[i] can be launched by the INIT process.

Location:
trunk/user
Files:
4 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/user/ksh/Makefile

    r407 r427  
    2121       $(LIBS)/build/stdlib.o   \
    2222       $(LIBS)/build/stdio.o    \
    23        $(LIBS)/build/nostdio.o  \
    2423       $(LIBS)/build/string.o   \
    2524       $(LIBS)/build/malloc.o   \
     
    5049        $(DU) -D $@ > $@.txt
    5150
    52 $(LIBS)/build/nostdio.o : $(LIBS)/nostdio.c $(LIBS)/nostdio.h
    53         $(CC) $(INCLUDES) $(CFLAGS) -c -o  $@ $<
    54         $(DU) -D $@ > $@.txt
    55 
    5651$(LIBS)/build/string.o : $(LIBS)/string.c $(LIBS)/string.h
    5752        $(CC) $(INCLUDES) $(CFLAGS) -c -o  $@ $<
  • trunk/user/ksh/ksh.c

    r418 r427  
    77///////////////////////////////////////////////////////////////////////////////
    88
    9 #include <nostdio.h>
    109#include <stdio.h>
    1110#include <stdlib.h>
     
    229228}   // end cmd_cp()
    230229
     230/////////////////////////////////////////
     231static 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
    231254//////////////////////////////////////////////
    232255static void cmd_help( int argc , char **argv )
     
    258281        }
    259282
    260         pid = atoi(argv[1]);
     283        pid = atoi( argv[1] );
     284
     285    if( pid == 0 )
     286    {
     287                printf("  error: ilegal pid format\n" );
     288        }
    261289
    262290        if( kill( pid , SIGKILL ) )
     
    264292                printf("  error: unable to kill process %x\n", pid );
    265293        }
    266 
    267     printf("\n   ...  done\n" );
    268 
    269294}   // end cmd_kill()
    270295
     
    272297static void cmd_load( int argc , char **argv )
    273298{
    274         unsigned int         pid;
    275     unsigned int         error;
     299        unsigned int         ret_pid;
     300    unsigned int         new_pid;
    276301        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] );
    281307                return;
    282308        }
     
    284310        pathname = argv[1];
    285311
     312    if( argc == 3 ) background = (argv[2][0] == '&');
     313
    286314    // fork system call
    287         pid = fork();
    288 
    289     if (pid == 0)  // it is the child process
     315        ret_pid = fork();
     316
     317    if (ret_pid == 0)  // it is the child process
    290318    {
    291319        // exec system call
    292         error = exec( pathname , NULL , NULL );
    293 
    294         if( error )
     320        if( exec( pathname , NULL , NULL ) )
    295321        {
    296322            printf("  error: new process unable to exec <%s>\n", pathname );
    297323            exit(0);
    298324        }
     325
     326        // get new process pid
     327        new_pid = getpid();
     328
     329        // give new process terminal ownership
     330        if( background == 0 ) fg( new_pid );
    299331        }
    300     else if ( pid < 0 )  // it is a failure reported to parent
     332    else if ( ret_pid < 0 )  // it is a failure reported to parent
    301333    {
    302334        printf("  error: unable to fork\n");
     
    443475}
    444476
    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/////////////////////////////////////////////////
     478static 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");
    463553    }
    464554}
     
    470560ksh_cmd_t cmd[] =
    471561{
    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         }
    487578};
    488579
  • trunk/user/pgcd/Makefile

    r417 r427  
    2020OBJS = pgcd.o                   \
    2121       $(LIBS)/build/stdlib.o   \
    22        $(LIBS)/build/nostdio.o  \
    2322       $(LIBS)/build/stdio.o    \
    2423       $(LIBS)/build/hal_user.o
     
    4645        $(DU) -D $@ > $@.txt
    4746
    48 $(LIBS)/build/nostdio.o : $(LIBS)/nostdio.c $(LIBS)/nostdio.h
    49         $(CC) $(INCLUDES) $(CFLAGS) -c -o  $@ $<
    50         $(DU) -D $@ > $@.txt
    51 
    5247clean:
    5348        rm -f *.o *.elf *.txt core $(LIBS)/build/*.o $(LIBS)/build/*.txt
  • trunk/user/pgcd/pgcd.c

    r417 r427  
    1616    int opx;
    1717    int opy;
     18    char c;
    1819
    1920    printf( "*** Starting interactive pgcd ***\n\n" );
  • trunk/user/sort/Makefile

    r417 r427  
    2323       $(LIBS)/build/pthread.o  \
    2424       $(LIBS)/build/malloc.o   \
    25        $(LIBS)/build/nostdio.o  \
    2625       $(LIBS)/build/hal_user.o
    2726
     
    5655        $(DU) -D $@ > $@.txt
    5756
    58 $(LIBS)/build/nostdio.o : $(LIBS)/nostdio.c $(LIBS)/nostdio.h
    59         $(CC) $(INCLUDES) $(CFLAGS) -c -o  $@ $<
    60         $(DU) -D $@ > $@.txt
    61 
    6257clean:
    6358        rm -f *.o *.elf *.txt core $(LIBS)/build/*.o $(LIBS)/build/*.txt
  • trunk/user/sort/sort.c

    r417 r427  
    2222///////////////////////////////////////////////////////////////////////////////
    2323
    24 #include <nostdio.h>
    2524#include <stdio.h>
    2625#include <stdlib.h>
Note: See TracChangeset for help on using the changeset viewer.