Ejemplo n.º 1
0
int zombie(int* arg) {
  int hp = 5000;
  int i;
  printf("Zombie %d.\n", minithread_id());
  for(i = 0; i < hp ; i++);

  return 0;
}
Ejemplo n.º 2
0
/**
 * This function does need to be protected because it is only called
 * from within a semaphore V, during which interrupts are disabled.
 * */
void
minithread_dequeue_and_run(queue_t q) {
  minithread_t blocked_thread = NULL;
  queue_dequeue(q, (void**)(&blocked_thread) );
  if (blocked_thread->status != BLOCKED) {
    printf("thread %d should have status BLOCKED\n", minithread_id());
  }
  minithread_start(blocked_thread);
}
Ejemplo n.º 3
0
int necromancer(int* arg) {
  int num_children = 2999;
  int i;
  printf("Necromancer %d spawning %d undead threads.\n", minithread_id(), num_children);
  for(i = 0; i < num_children; i++){
    minithread_fork(zombie, NULL);
  }
  printf("Come, my servants!\n");
  minithread_yield();
  printf("Fascinating.\n");

  return 0;
}
Ejemplo n.º 4
0
int shell(int *g) {
	char command[BUFFER_SIZE];
	char func[BUFFER_SIZE],arg1[BUFFER_SIZE],arg2[BUFFER_SIZE];
	int i;

	minifile_cd("/"); //cd to root (will also initialize the system if necessary)
	printf("%s\n", IDstring);

	while(1) {
		memset(command,'\0',BUFFER_SIZE);
		memset(func,'\0',BUFFER_SIZE);
		memset(arg1,'\0',BUFFER_SIZE);
		memset(arg2,'\0',BUFFER_SIZE);
		put_prompt();
		gets(command);
		//extract first three strings in command (delimited by spaces)
		sscanf(command,"%s %s %s",func,arg1,arg2);
		if(strcmp(func,"help") == 0)
			help_screen();
		else if(strcmp(func,"cd") == 0)
			minifile_cd(arg1);
		else if(strcmp(func,"ls") == 0 || strcmp(func,"dir") == 0) {
		  char **files = minifile_ls(arg1);
		  printf("File listing for %s\n", arg1);
		  for(i = 0; files != NULL && files[i] != NULL; ++i) {
		    printf("\t%s\n",files[i]);
		    free(files[i]);
		  }
		  if(files != NULL)
		    free(files);
		} else if(strcmp(func,"pwd") == 0)
		        printf("%s\n", minifile_pwd());
		else if(strcmp(func,"mkdir") == 0)
		        minifile_mkdir(arg1);
		else if(strcmp(func,"rmdir") == 0)
			minifile_rmdir(arg1);
		else if(strcmp(func,"rm") == 0 || strcmp(func,"del") == 0)
			minifile_unlink(arg1);
		else if(strcmp(func,"import") == 0)
			importfile(arg1,arg2);
		else if(strcmp(func,"export") == 0)
			exportfile(arg1,arg2);
		else if(strcmp(func,"type") == 0)
			typefile(arg1);
		else if(strcmp(func,"input") == 0)
			inputfile(arg1);
		else if(strcmp(func,"cp") == 0 || strcmp(func,"copy") == 0)
			copy(arg1,arg2);
		else if(strcmp(func,"mv") == 0 || strcmp(func,"move") == 0)
			move(arg1,arg2);
		else if(strcmp(func,"whoami") == 0)
			printf("You are minithread %d, running our shell\n",minithread_id());
		else if(strcmp(func,"exit") == 0)
			break;
		else if(strcmp(func,"doscmd") == 0)
			system(command+7);
		else if(strcmp(func,"exec") == 0) { //this is not efficient -- just for fun!!!
			char cmdline[BUFFER_SIZE];
			memset(cmdline,'\0',BUFFER_SIZE);
			strcpy(cmdline,"tmp0000~.exe ");
			strcpy(cmdline+13,command+5+strlen(arg1));
			exportfile(arg1,"tmp0000~.exe");
			system(cmdline);
			system("rm tmp0000~.exe");
		}
		else printf("%s: Command not found\n",func);
	}
	printf("Good-bye :-)\n");
	return 0;
}
Ejemplo n.º 5
0
void put_prompt() {
	printf("%d@localhost: %s %%",minithread_id(), minifile_pwd());
}
Ejemplo n.º 6
0
void put_prompt()
{
    printf("thread%d@localhost", minithread_id());
    printf(": %s %% ", minifile_pwd());
    fflush(stdout);
}