Example #1
0
int Main( int argc , char ** argv )
{
  int policy;
  int quantum;

  int id1, id2, id3;    	/* ID of child process */

    if (argc == 3) {
      if (!strcmp(argv[1], "rr")) {
          policy = SCHEDPOLICY_RR;
      } else if (!strcmp(argv[1], "mlf")) {
          policy = SCHEDPOLICY_MF;
      } else {
	  Printf("usage: %s [rr|mlf] <quantum>\n", argv[0]);
	  Exit();
      }
      quantum = atoi(argv[2]);
      Set_Scheduling_Policy(policy, quantum);
  } else {
      Printf("usage: %s [rr|mlf] <quantum>\n", argv[0]);
      Exit();
  }

  id3 = Spawn_Program ( "/c/sched3.exe" ) ;
  id1 = Spawn_Program ( "/c/sched1.exe" ) ;
  id2 = Spawn_Program ( "/c/sched2.exe" ) ;

  
  Wait(id1);
  Wait(id2);
  Wait(id3);
  Printf("\n");
  return 0;
}
Example #2
0
int main( int argc , char ** argv )
{
  int scr_sem,holdp3_sem;	/* sid of screen semaphore */
  int id1, id2, id3;    	/* ID of child process */
  
  holdp3_sem = Open_Semaphore ("holdp3_sem", 0);
  scr_sem    = Open_Semaphore ( "screen" , 1 )  ;
  

  P ( scr_sem ) ;
  Print ("Semtest1 begins\n");
  V ( scr_sem ) ;


  id3 = Spawn_Program ( "/c/sem-p3.exe", "/c/sem-p3.exe", 0 ) ;
  P ( scr_sem ) ;
  Print ("p3 created\n");
  V ( scr_sem ) ;
  id1 = Spawn_Program ( "/c/sem-p1.exe", "/c/sem-p2.exe", 0 ) ;
  id2 = Spawn_Program ( "/c/sem-p2.exe", "/c/sem-p1.exe", 0 ) ;
  

  Wait(id1);
  Wait(id2);
  Wait(id3);

  Close_Semaphore(scr_sem);
  Close_Semaphore(holdp3_sem);
  return 0;
}
Example #3
0
int Main( int argc , char ** argv )
{
  int policy;
  int start;
  int elapsed;
  int quantum;
  int scr_sem;			/* sid of screen semaphore */
  int id1, id2, id3;    	/* ID of child process */

  if (argc == 3) {
      if (!strcmp(argv[1], "rr")) {
          policy = SCHEDPOLICY_RR;
      } else if (!strcmp(argv[1], "mlf")) {
          policy = SCHEDPOLICY_MF;
      } else {
	  Printf("usage: %s [rr|mlf] <quantum>\n", argv[0]);
	  Exit();
      }
      quantum = atoi(argv[2]);
      Set_Scheduling_Policy(policy, quantum);
  } else {
      Printf("usage: %s [rr|mlf] <quantum>\n", argv[0]);
      Exit();
  }

  start = Get_Time();
  scr_sem = Init_Semaphore ( "screen" , 1 )  ;

  P ( scr_sem ) ;
  Printf ("************* Start Workload Generator *********\n");
  V ( scr_sem ) ;

  id1 = Spawn_Program ( "/c/long.exe" ) ;
  P ( scr_sem ) ;
  Printf ("Process Long has been created with ID = %d\n",id1);
  V ( scr_sem ) ;


  id2 = Spawn_Program ( "/c/ping.exe" ) ;

  P ( scr_sem ) ;
  Printf ("Process Ping has been created with ID = %d\n",id2);
  V ( scr_sem ) ;

  id3 = Spawn_Program ( "/c/pong.exe" ) ;
  P ( scr_sem ) ;
  Printf ("Process Pong has been created with ID = %d\n",id3);
  V ( scr_sem ) ;

  Wait(id1);
  Wait(id2);
  Wait(id3);

  elapsed = Get_Time() - start;
  Printf ("\nTests Completed at %d\n", elapsed) ;
  return 0;
}
Example #4
0
int main(int argc , char ** argv)
{
  int ping_pid, pong_pid;    	/* ID of child process */

  Print ("\nStarting ping-pong tests...\n") ;

  ping_pid = Spawn_Program ("/c/ping6.exe", "/c/ping6.exe");
  pong_pid = Spawn_Program ("/c/pong6.exe", "/c/pong6.exe");

  Wait(ping_pid);
  Wait(pong_pid);

  Print ("\nPing-pong tests completed.\n") ;

  return 0;
}
Example #5
0
void Main(void)
{
    int fd;
    int sink, source;

    fd = MessageQueueCreate("pipe1");
    Print("create mq returned %d\n", fd);

    source = Spawn_Program ("/c/cat.exe /c/file1", 0, fd);
    sink = Spawn_Program ("/c/wc.exe", fd, 1);
    Close(fd);

    Wait(sink);
    Wait(source);
    Exit();
}
Example #6
0
int main(int argc, char **argv) {
    int policy = -1;
    int start;
    int elapsed;
    int scr_sem;                /* sid of screen semaphore */
    int id1, id2, id3;          /* ID of child process */

    if(argc == 2) {
        if(!strcmp(argv[1], "rr")) {
            policy = 0;
        } else if(!strcmp(argv[1], "mys")) {
            policy = 1;
        } else {
            Print("usage: %s [rr|mys]\n", argv[0]);
            Exit(1);
        }
        Set_Scheduling_Policy(policy, 20);
    } else {
        Print("usage: %s [rr|mys]\n", argv[0]);
        Exit(1);
    }

    start = Get_Time_Of_Day();
    scr_sem = Open_Semaphore("screen", 1);

    P(scr_sem);
    Print("************* Start Workload Generator *********\n");
    V(scr_sem);

    id1 = Spawn_Program("/c/long.exe", "/c/long.exe", 0);
    P(scr_sem);
    Print("Process Long has been created with ID = %d\n", id1);
    V(scr_sem);


    id2 = Spawn_Program("/c/long.exe", "/c/long.exe", 0);

    P(scr_sem);
    Print("Process Long #1 has been created with ID = %d\n", id2);
    V(scr_sem);

#ifdef notdef
    id2 = Spawn_Program("/c/ping.exe", "/c/ping.exe", 0);

    P(scr_sem);
    Print("Process Ping has been created with ID = %d\n", id2);
    V(scr_sem);

    id3 = Spawn_Program("/c/pong.exe", "/c/pong.exe", 0);
    P(scr_sem);
    Print("Process Pong has been created with ID = %d\n", id3);
    V(scr_sem);
#endif

    Wait(id1);
    Wait(id2);
    // Wait(id3);

    elapsed = Get_Time_Of_Day() - start;
    Print("\nTests Completed at %d\n", elapsed);
    return 0;
}
Example #7
0
void Spawner( unsigned long arg )
{
  const char *program = "/c/a.exe";
  char *exeFileData = 0;
  ulong_t exeFileLength;
  struct Exe_Format exeFormat;
 

  /*
   * Load the executable file data, parse ELF headers,
   * and load code and data segments into user memory.
   */

  if (lprogdebug)
    {
      Print("Reading %s...\n", program);
    }

  if (Read_Fully(program, (void**) &exeFileData, &exeFileLength) != 0)
    {
      Print("Read_Fully failed to read %s from disk\n", program);
      goto fail;
    }

  if (lprogdebug)
    {  
      Print("Read_Fully OK\n");
    }

  if (Parse_ELF_Executable(exeFileData, exeFileLength, &exeFormat) != 0)
    {
      Print("Parse_ELF_Executable failed\n");
      goto fail;
    }


  if (lprogdebug)
    { 
      Print("Parse_ELF_Executable OK\n");
    }

  if (Spawn_Program(exeFileData, &exeFormat) != 0)
    {
      Print("Spawn_Program failed\n");
      goto fail;
    }


    /*
     * User program has been loaded, so we can free the
     * executable file data now.
     */
    Free(exeFileData);
    exeFileData = 0;

  /* If we arrived here, everything was fine and the program exited */

  Print("Hi ! This is the third (and last) string\n");
  Print("If you see this you're happy\n");

  Exit(0);

fail:
    /* We failed; release any allocated memory */
    Disable_Interrupts();

    Free(virtSpace);

    Enable_Interrupts();
}
Example #8
0
int Main (int argc , char ** argv)
{
  int i;
  int ret;
  int done;
  int eoln;
  int debug;
  char *curr;
  char *dest;
  char line[256];
  int infd, outfd;
  char tempName[2];
  char strName[20];
  int numCommand;
  int   count ;         /* child process's argc */
  char command[256];

  done = 0;
  while (!done) {
     Printf("shell %% ");

     eoln = 0;
     count = 0;

     Read_Line( line, sizeof(line) );

     line[strlen(line)-1] = '\0';

     /* blank line */
     if (!strcmp(line, "")) continue;

     if (!strcmp(line, "exit")) {
         return 0;
     } else if (!strcmp(line, "debug")) {
	 debug = 1;
	 continue;
     } else if (!strcmp(line, "nodebug")) {
	 debug = 0;
	 continue;
     }

    split(line, &numCommand);
    infd = 0;
    outfd = 1;

    for (i=0; i < numCommand-1; i++) {
        if (commands[i].outFile) {
	    Printf("Error: file redirection for command other than last one in pipeline\n");
	    break;
	}
    }
    if (i != numCommand-1) continue;

    if (debug) {
	for (i=0; i < numCommand; i++) {
	    Printf("command %d = %s\n", i, commands[i].command);
	}
    }

    for (i=0; i < numCommand; i++) {
 	 if (outfd != 1) infd = outfd;

         if (i == numCommand-1)  {
	     if (commands[i].outFile) {
		 /* last one goes to a file */
		 outfd = Open(commands[i].outFile, O_WRITE|O_CREATE);
		 if (outfd < 0) {
		     Printf("Error opening %s\n", commands[i].outFile);
		 }
	     } else {
		 /* last one goes to stdout */
		 outfd = 1;
	     }
	 } else {
             strcpy(strName, "/dev/pipe");
	     tempName[0] = count + '0';
	     count++;
	     tempName[1] = '\0';
	     strcat(strName, tempName);
 	     outfd = MessageQueueCreate(strName);
	     if (outfd < 0) {
	         Printf("pipe failed\n");
		 continue;
	     }
	 }

         /* now run it */
	 memset(command, '\0', sizeof(command));
         if (commands[i].command[0] != '/') {
	     //	add implict path to /c for programs
	     strcpy(command, "/c/");
             for (curr=commands[i].command, dest=&command[3]; *curr; curr++) {
                if (*curr == ' ') break;
                *(dest++) = *curr;
             }
             strcat(command, ".exe");
             strcat(command, curr);
             // Printf("command is %s\n", command);
         } else {
             strcpy(command, commands[i].command);
         }

         commands[i].pid = Spawn_Program ( command , infd, outfd);
         if ( commands[i].pid <= 0 )  {  /* Unable to proc_start */
            Printf ( "%s: Command not found\n", commands[i].command) ;
            continue;
         } else {
	    if (debug) Printf("spawned pid %d, command = %s\n", 
		commands[i].pid, commands[i].command);
   	    if (infd != 0) Close(infd);
	 }
    }

    /* now wait for them all to finish */
    for (i=0; i < numCommand; i++) {
	if (commands[i].pid > 0) {
	    ret = Wait(commands[i].pid);
	    if (debug) Printf("process %d exited\n", commands[i].pid);
	}
    }
    if (debug) Printf("all processes exited\n");
  }

  return 0;
}