示例#1
0
文件: semtest1.c 项目: Foshie/Classes
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;
}
示例#2
0
文件: sem-ping.c 项目: Foshie/Classes
int main(int argc , char ** argv)
{
  int i,j ;     	/* loop index */
  int scr_sem; 		/* id of screen semaphore */
  int time; 		/* current and start time */
  int ping,pong;	/* id of semaphores to sync processes b & c */

  time = Get_Time_Of_Day();
  scr_sem = Open_Semaphore ("screen" , 1) ;   /* register for screen use */
  ping = Open_Semaphore ("ping" , 1) ;   
  pong = Open_Semaphore ("pong" , 0) ;  

  for (i=0; i < 5; i++) {
       P(pong);

       P (scr_sem);
       Print ("Ping\n");
       V(scr_sem);
       
       for (j=0; j < 35; j++);
       V(ping);
  }

  time = Get_Time_Of_Day() - time;
  P (scr_sem) ;
  Print ("Process Ping is done at time: %d\n", time) ;
  V(scr_sem);

  Close_Semaphore(pong);
  Close_Semaphore(ping);
  Close_Semaphore(scr_sem);

  return (0);

}
示例#3
0
文件: sem-p3.c 项目: Foshie/Classes
int main(int argc, char** argv)
{
  int scr_sem,holdp3_sem;
  scr_sem = Open_Semaphore ( "screen" , 1 ) ;   /* register for screen use */
  holdp3_sem = Open_Semaphore ("holdp3_sem", 0);

  P(holdp3_sem);

  P ( scr_sem ) ;
  Print("p3 executed\n");
  V( scr_sem );

  V(holdp3_sem);
  
  Close_Semaphore(scr_sem);
  Close_Semaphore(holdp3_sem);

  return 0;  
}
示例#4
0
文件: sched3.c 项目: Foshie/Classes
int main( int argc , char ** argv )
{

  int holdsched3_sem;

  holdsched3_sem = Open_Semaphore("holdsched3_sem",0);

  P(holdsched3_sem);
  Print("3");
  V(holdsched3_sem);

  Close_Semaphore(holdsched3_sem);
  return 0;
}
示例#5
0
文件: sem-p1.c 项目: Foshie/Classes
int main( int argc , char ** argv )
{

  int i ;     	/* loop index */
  int scr_sem; 		/* id of screen semaphore */
  int prod_sem,cons_sem;	

  scr_sem = Open_Semaphore ( "screen" , 1 ) ;   /* register for screen use */
  prod_sem = Open_Semaphore ( "prod_sem" , 0 ) ;   
  cons_sem = Open_Semaphore ( "cons_sem" , 1 ) ;  

  for (i=0; i < 5; i++) {
    P(cons_sem);
    Print ("Produced %d\n",i) ;
    V(prod_sem);
  }
  
  Close_Semaphore(scr_sem);
  Close_Semaphore(prod_sem);
  Close_Semaphore(cons_sem);

  return 0;
}
示例#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;
}
示例#7
0
 */
#include <conio.h>
#include <process.h>
#include <sched.h>
#include <sema.h>
#include <string.h>

int main(int argc __attribute__ ((unused)), char **argv
         __attribute__ ((unused))) {
    int i, j;                   /* loop index */
    int scr_sem;                /* id of screen semaphore */
    int time;                   /* current and start time */
    int ping, pong;             /* id of semaphores to sync processes b & c */

    time = Get_Time_Of_Day();
    scr_sem = Open_Semaphore("screen", 1);      /* register for screen use */
    ping = Open_Semaphore("ping", 1);
    pong = Open_Semaphore("pong", 0);

    for (i = 0; i < 5; i++) {
        P(ping);

        P(scr_sem);
        Print("Pong\n");
        V(scr_sem);

        for (j = 0; j < 35; j++);
        V(pong);
    }

    time = Get_Time_Of_Day() - time;
示例#8
0
 * Copyright (c) 2003,2013,2014 Jeffrey K. Hollingsworth <*****@*****.**>
 *
 * All rights reserved.
 *
 * This code may not be resdistributed without the permission of the copyright holders.
 * Any student solutions using any of this code base constitute derviced work and may
 * not be redistributed in any form.  This includes (but is not limited to) posting on
 * public forums or web sites, providing copies to (past, present, or future) students
 * enrolled in similar operating systems courses the University of Maryland's CMSC412 course.
 */
#include <conio.h>
#include <process.h>
#include <sched.h>
#include <sema.h>
#include <string.h>

int main(int argc __attribute__ ((unused)), char **argv
         __attribute__ ((unused))) {

    int holdsched3_sem;

    holdsched3_sem = Open_Semaphore("holdsched3_sem", 0);

    P(holdsched3_sem);
    Print("3");
    V(holdsched3_sem);

    Close_Semaphore(holdsched3_sem);
    return 0;
}