Exemple #1
0
Fichier : t.c Projet : shank8/CS460
main()
{
 /* initialize();
 PROC p[5];

 int i=0;
 for(i=0;i<5;i++){
  p[i].priority = i;
  p[i].pid = 5-i;
  enqueue(&p[i], &readyQueue);
 }
*/
 

 printf("\nWelcome to the 460 Multitasking System\n");
    initialize();
    printf("P0 forks P1\n");

  kfork();  // fork P1 
  printf("P0 switches to P1... calling tswitch()\n"); 
    tswitch();  // switches running to P1

  // Switch, Quit & Fork processes until all of them are dead except P0
  printf("Almost done... running is P%d\n", running->pid); 
  printf("P0 resumes: all dead, happy ending\n");

 // printf("Lets go to the %s to get %d %s for %d %ss\n", "store", 5, "steaks", 8, "dinner");
}
Exemple #2
0
int body()
{ 
char c;
int event;
while(1){
	printf("\n***************************************\n");
	print();
	printf("\nI am task %d My parent=%d\n", running->pid, running->ppid);
	printf("input a char [fork:f|switch:s|exit:q|sleep:z|wakeup:a|wait:w] : ");  
	c = getchar();
	switch(c){
		case 'f': kfork();      break;
		case 's': tswitch();    break;
		case 'q': kexit(0); 	break;
		case 'z': {printf("enter event to put process to sleep");
			  scanf("%d",&event);		
			  ksleep(event);}	
			  break;
		case 'a': {printf("enter event to wake up process");
			  scanf("%d",&event);		
			  kwakeup(event);}	
			  break;
		case 'w': kwait(0); 	break;
		default: printf("invalid char\n"); break;
		}	
	}
return;
}
Exemple #3
0
/*************** kernel command functions ****************/
int do_kfork( )
{
    PROC *p = kfork();
    if (p == 0){ myprintf("kfork failed\n"); return -1; }
    myprintf("PROC %d kfork a child %d\n", running->pid, p->pid);
    return p->pid;
}
Exemple #4
0
main()
{ 
  char name[64]; int pid, cmd;
color = 0x0F;
  while(1){
    printf("----------------------------------------------\n");
    pid = getpid();
    
     printf("I am proc %d in U mode: running segment=%x\n", pid, getcs());
    show_menu();
    printf("Command ? ");

    gets(name); 
    if (name[0]==0) 
        continue;

    cmd = find_cmd(name);
    switch(cmd){
           case 0 : getpid();   break;
           case 1 : ps();       break;
           case 2 : chname();   break;
           case 3 : pid = kfork();   
           printf("fork returned: %d\n", pid);
            break;
           case 4 : kswitch();  break;
           case 5 : wait();     break;
           case 6 : exit();     break;
           case 7 : pid = exec();   
           printf("exec returned: %d\n", pid);  break;

           default: invalid(name); break;
    }
  }
}
//main function, execution starts here
main()
{
    int i = 0;
    vid_init();//initialize video

    printf("MTX starts in main()\n");
    init(); // initialize and create P0 as running
    set_vector(80, int80h);

    kfork("/bin/u1");     // P0 kfork() P1

    set_vector(9, kbinth);
    kbd_init();

    //timer init
    lock();
    set_vector(8,tinth);
    timer_init();

    while(1)
    {
      unlock();
      if(readyQueue)
          tswitch();
      else
          halt();
   }
}
Exemple #6
0
Fichier : t.c Projet : Cj-muse/Lab4
int body(void)
{
   char c, str[64];

   printf("proc %d resumes to body()\n\r", running->pid);
   showLists();
   while(1)
   {
      printf("\rproc %d running : enter a key [s|f|z|a|w|q|u|p|l]: ", running->pid);
      c = getc();
      printf("%c\n\r", c);
      switch(c)
      {
         case 's': tswitch();  break;
         case 'q': do_exit();  break;
         case 'f': kfork("/bin/u1");    break;
         case 'z': do_sleep(); break;
         case 'a': do_wake();  break;
         case 'w': do_wait();  break;
         case 'u': goUmode();  break;
         case 'p': do_ps();    break;
         case 'l': showLists();break;
         default: break;
      }
   }
}
Exemple #7
0
// figure out what the user wants to do!
int body()
{
    char c;
    while(1)
    {
        color = 0x01 + (running->pid % NPROC); // change the text color based on the process id!
        printf("\n******************************\n");
        printf("Currently Running Process #%d", running->pid);
        printf("\nReady Queue: ");
        printQueue(readyQueue);
        printf("******************************\n");
        printf("Input a command [s | q | f | r | ?]:");
        c = getc();
        printf("\n");
        switch (c)
        {
            case 's': tswitch(); break;
            case 'q': zombify(); break;
            case 'f': kfork(); break;
            case 'r': resurrect(); break;
            case '?': help(); break;
            default: break;
        }
    }
}
Exemple #8
0
main()
{ 
  char name[64]; int pid, cmd;
  char c;

  while(1){
    
    color = 0x0C;
       
    printf("----------------------------------------------\n");
    pid = getpid();
    printf("I am proc %d in U mode: running segment=%x\n", pid, getcs());
    show_menu();
    printf("Command ? ");
    gets(name); 
    if (name[0]==0) 
        continue;

    cmd = find_cmd(name);
    switch(cmd){
           case 0 : getpid();   break;
           case 1 : ps();       break;
           case 2 : chname();   break;
           case 3 : kfork();    break;
           case 4 : kswitch();  break;
           case 5 : wait();     break;
           case 6 : exit();     break;
           case 7 : c = kgetc();  putc(c); putc('\n'); putc('\r'); break;
           case 8 : kputc();    break;

           default: invalid(name); break;
    }
  }
}
Exemple #9
0
// execute kfork and check return
int do_kfork(){
	int i;
	i = kfork("bin/u1");
	if (i < 0)
		printf("fork failed\n");
	else
		printf("parent return from fork, child=%d\n", i);
}
int do_kfork(){
	PROC *p = kfork();
	if (p == 0){
		printf("kfork failed\n");
		return -1;
	}

	return p->pid;
}
Exemple #11
0
/***************************************************************
  myfork(segment) creates a child task and returns the child pid.
  When scheduled to run, the child task resumes to body(pid) in 
  K mode. Its U mode environment is set to segment.
****************************************************************/
int myfork()
{  
   int child;
   child = kfork("/bin/u1");
   if (child < 0){
       printf("myfork failed\n"); 
       return;
   } 
   printf("task %d return from myfork() : child=%d\n", running->pid, child);
}
Exemple #12
0
/**
 * Fork user-mode PROC as mirror image of itself.
 * @return Child PID (failure: -1)
 */
int fork() {
    PROC *ptr = kfork(0);   	// kfork() but do NOT load any Umode image for child 
    
    if (ptr == 0) {           	// kfork failed
        printf("Failed to kfork()\n");
	return(-1);
    }
    
    return(ptr->pid);
}
Exemple #13
0
main()
{
    myprintf("MTX starts in main()\n");
    init();                 // initialize and create P0 as running
    kfork();                // P0 creates child P1
    while(1){               // P0 switches if readyQueue not empty
        if (readyQueue)
            tswitch();
    }
}
Exemple #14
0
int do_kfork()
{
  PROC *p;
  printf("KillModule%d kfork a child\n", running->pid);
  p = kfork("/bin/u1");
  if (p==0)
     printf("kfork failed\n");
  else
     printf("child pid = %d\n", p->pid);
}
Exemple #15
0
int do_kfork()
{
  int pid;
  printf("proc%d kfork a child\n");
  pid = kfork("/bib/u1");
  if (pid < 0)
    printf("kfork failed\n");
  else
    printf("child pid = %d\n", pid);
}
Exemple #16
0
int fork()
{
	PROC *p;  int i, child, pid;  u16 segment;

	pid = kfork(0);   // kfork() but do NOT load any Umode image for child
	if (pid < 0){     // kfork failed
		return -1;
	}
	p = &proc[pid];   // we can do this because of static pid

	for (i=0; i<NFD; i++){
		p->fd[i] = running->fd[i];

		if (p->fd[i] != 0){
			p->fd[i]->refCount++;

			if (p->fd[i]->mode == READ_PIPE)
				p->fd[i]->pipe_ptr->nreader++;

			if (p->fd[i]->mode == WRITE_PIPE){
				p->fd[i]->pipe_ptr->nwriter++;
			}
		}
	}

	segment = (pid+1)*0x2000;
	copyImage(running->uss, segment, 32*1024);
	p->uss = segment;
	p->usp = 0x2000 - 24;

	// YOUR CODE to make the child runnable in User mode
	p->kstack[SSIZE -1] =(int)goUmode;
	/**** ADD these : copy file descriptors ****/

	// clean the registers and set flag and uCs and uDs to runnings values
	for (i = 1; i < 13; i++) {
		child = 0x2000 - i*2;
		switch(i){
			case 1: put_word(segment, segment, child); break;
			case 2: put_word(segment, segment, child); break;
			case 3:
			case 4:
			case 5:
			case 6:
			case 7:
			case 8:
			case 9:
			case 10: put_word(0,segment, child); break;
			case 11:
			case 12: put_word(segment, segment, child); break;
		}
	}

	return(p->pid);
}
Exemple #17
0
main()
{
    char m;
    vid_init();
    printf("MTX starts in main()\n");
    init();      // initialize and create P0 as running
    set_vector(80, int80h);

    set_vector(12, s0inth); // vector 12 for COM1
    set_vector(11, s1inth); // vector 11 for COM2
    sinit();

    set_vector(9, kbinth);
    kbd_init();


    lock();
    set_vector(8, tinth);
    timer_init();


    mode = LIVE; //used for demoing the time working, set to DEMO to see four procs switch by themselves

    kfork("/bin/u1");     // P0 kfork() P1

    if(mode == DEMO)
    {
        kfork("/bin/u1");
        kfork("/bin/u1");
        kfork("/bin/u1");
    }

    while(1){
        //printf("P0 running\n");
        while(!readyQueue);
            //printf("P0 switch process\n");
            running->status = READY;
            tswitch();         // P0 switch to run P1
   }
}
Exemple #18
0
int main() {
	extern PROC *readyQueue;
	extern PROC *running;
	extern PROC proc[NPROC];
	int i;

	MTXInit();
	#ifdef _SLEEPER_
		for(i = 0; i < 5; i++) kfork("/bin/u1");
	#else
		kfork("/bin/u1");
	#endif

	printf("P%d is now going to enter infinite loop!\n", running->pid);
	while(1) {
		printf("P%d is now waiting for something in the queue...\n", running->pid);
		while( ! readyQueue);
		printf("P%d is now going to switch!\n", running->pid);
		tswitch();
		printf("P%d is now running\n", running->pid);
	}
}
Exemple #19
0
main(){
	printf("MTX starts in main()\n");
	init();      // initialize and create P0 as running
	set_vec(80, int80h);

	kfork("/bin/u1");     // P0 kfork() P1

	while(1){
		printf("P0 running\n");
		while(!readyQueue);
		printf("P0 switch process\n");
		tswitch();         // P0 switch to run P1
	}
}
//start execution here
main()
{
	printf("MTX starts in main()\n");
	
	init();                 // initialize and create P0 as running
	kfork();                // P0 creates child P1
	
	while(1)				// P0 switches if readyQueue not empty
	{
		if (readyQueue)
			tswitch(); //goes to body
		printf("asdfasdf\n");
	}
	printf("process 0 is still running\n");
}
Exemple #21
0
//////////// 2.
// run the os!
main()
{
    printf("\nWelcome to the CS460 Multitasking System New User!\n");
    
    printf("initializing...");
    initialize();
    
    printf("forking...");
    kfork();
    
    printf("switching...");
    tswitch();
    
    printf("\nGoodbye User!\n");
}
Exemple #22
0
int vfork()
{
  PROC *p;  int pid;  u16 segment;
  int i, w;
  printf("vfork() in kernel\n");
  pid = kfork(0);   // kfork() but do NOT load any Umode image for child 
  if (pid < 0){     // kfork failed 
    return -1;
  }
  p = &proc[pid];   // we can do this because of static pid

  /*******************************************************************  
  entend parents ustack with another syscall frame for child to return with
  -------------------------------------------------------
       |cds ces ......cax....<===..|pds pes ........cax f    |         
  ------------------------------------------------------
        cusp                    pusp            frame from pid=vfork()

  cusp = running->usp -24; <== more also need the return frames before INT 80
  copy psup 24 bytes to cusp:

/*************************************************************************
  usp  1   2   3   4   5   6   7   8   9  10   11   12    13  14  15  16
----------------------------------------------------------------------------
 |uds|ues|udi|usi|ubp|udx|ucx|ubx|uax|upc|ucs|uflag|retPC| a | b | c | d |
----------------------------------------------------------------------------
***************************************************************************/
  
  printf("fix ustack for child to return to Umode\n");

  for (i=0; i<24; i++){  // 24=13+9 is enough > 24 should also work
     w = get_word(running->uss, running->usp+i*2);
         put_word(w, running->uss, running->usp-1024+i*2);
  }

  p->uss = running->uss;
  p->usp = running->usp - 1024;

  //printf("%x  %x   %x  %x\n", running->uss, running->usp, p->uss, p->usp);

  put_word(0,running->uss,p->usp+8*2);

  p->kstack[SSIZE-1] = goUmode; 

  printList("readyQueue ", readyQueue);

  return(p->pid);
}
Exemple #23
0
int main()
{
printf("init\n");
init();

printQueue(freeList);
printf("\nkfork\n");
kfork("/bin/u1");   // create P1
printf("\nP0 switch to P1\n");

while(1)
{
	if(readyQueue)
		tswitch();
}
}
Exemple #24
0
Fichier : t.c Projet : shank8/CS460
int body()
{  char c;
   while(1){
     ps();
     
      printf("I am Proc %d in body()\n", running->pid); 
      printf("Input a char : [s|q|f] ");
       c=getc();
       switch(c){
            case 's': tswitch(); break;
            case 'q': grave();   break;
            case 'f': kfork();   break;
            default :            break;
       }
   }
}
//as shown in KC's textbook
int do_kfork()
{
	//get pointer to child process from kfork()
	PROC *p = kfork();

	//if 0, then the fork failed!
	if (p == 0)
	{
		printf("ERROR: kfork failed\n"); //error message
		return -1;
	}
	
	//print results
	printf("PROC %d kfork a child %d\n", running->pid, p->pid);
	//return the pid of the newly forked process
	return p->pid;
}
Exemple #26
0
main()
{
    printf("MTX starts in main()\n");
    init();      // initialize and create P0 as running
    set_vec(80,int80h);

   set_vec(15, pinit);
  

    kfork("/bin/u1");     // P0 kfork() P1
    while(1){
      if (readyQueue)
	tswitch();
      else
	halt();
    }
}
//start execution here
main()
{
	printf("MTX starts in main()\n");
	
	init();                 // initialize and create P0 as running
	kfork();                // P0 creates child P1
	
	while(1)				// P0 switches if readyQueue not empty
	{
		printf("P0 running\n");
		if (nproc == 2 && proc[1].status != READY)
			printf("no runable process, system halts\n");
		while(!readyQueue);
		printf("P0 switch process\n");
		tswitch(); //tswitch to run P1
	}
}
Exemple #28
0
main()
{
  printf("MTX starts in main()\n");
  init();
  kfork();
  tswitch();
  body();
  while(1){
    printf("proc 0  running : enter a key : \n");
    getc();
	if (readyQueue){
    	tswitch();
	}
	else{
		printf("proc 0 running: enter a key: \n");
	}
  }
}
//main function, execution starts here
main()
{
    printf("MTX starts in main()\n");
    init(); // initialize and create P0 as running
    set_vector(80, int80h);

    kfork("/bin/u1");     // P0 kfork() P1

    while(1)
    {
      printf("P0 running\n");
      if (nproc == 2 && proc[1].status != READY)
          printf("no runable process, system halts\n");
      while(!readyQueue);
      printf("P0 switch process\n");
      tswitch();         // P0 switch to run P1
   }
}
Exemple #30
0
int kkfork()
{
  //use you kfork() in kernel;
  //return child pid or -1 to Umode!!!

   PROC *p;
  printf("proc %d kfork a child ", running->pid);
  p = kfork(0);  // every proc has /bin/u1 as Umode image
  if (p == 0){
     printf("kfork failed\n");
     return -1;
  }
  else{
    printf("child pid = %d\n", p->pid);
    return p->pid;

  }

}