Пример #1
0
int
main(int argc, char *argv[]){
  int n, pid, i , j, h;
  int stime_cpu = 0,stime_scpu = 0, stime_IO = 0;
  int retime_cpu = 0, retime_scpu = 0, retime_IO  = 0;
  int tatime_cpu = 0, tatime_scpu = 0, tatime_IO = 0;
  int retime, rutime, stime;
  enum test_type test;

  if (argc != 2) 
    return -1;
  n = atoi(argv[1]);
  for(i = 0 ; i < 3 * n ; ++i) {
    pid = fork();
    if(pid == 0) {
      test = getpid() % 3;
      if(test == CPU) {
        for(j = 0 ; j < 100 ; ++j)
          for(h = 0 ; h < 1000000 ; ++h){}
      } 
      else if(test == S_CPU) {
        for(j = 0 ; j < 100 ; ++j) {
          for(h = 0 ; h < 1000000 ; ++h){}
          yield();
        }
      } 
      else { //IO
        for(j = 0 ; j < 100 ; ++j)
          sleep(1);
      }
      exit();
    }
    else if (pid < 0) {
      printf(1, "fork number %d, failed!!! \n", i);
    }
    else{} 
  }
  while((pid =wait2(&retime, &rutime, &stime)) > 0) { // pid != 0 (parent code)
    test = pid % 3;
    printf(1, "process id: %d, type: %s \n", pid, get_test_name(test));
    printf(1,"wait time: %d, run time: %d, IO time: %d \n",
        retime, rutime, stime);
    switch(test) {
      case CPU:
        stime_cpu += stime;
        retime_cpu += retime;
        tatime_cpu += stime + retime + rutime;
        break;
      case S_CPU:
        stime_scpu += stime;
        retime_scpu += retime;
        tatime_scpu += stime + retime + rutime;
        break; 
      case IO:
        stime_IO += stime;
        retime_IO += retime;
        tatime_IO += stime + retime + rutime;
        break;
    } 

  }

  sleeptime(CPU,n,stime_cpu);
  sleeptime(S_CPU,n,stime_scpu);
  sleeptime(IO,n,stime_IO);

  readytime(CPU,n,retime_cpu);
  readytime(S_CPU,n,retime_scpu);
  readytime(IO,n,retime_IO);

  turnaroundtime(CPU,n,tatime_cpu);
  turnaroundtime(S_CPU,n,tatime_scpu);
  turnaroundtime(IO,n,tatime_IO);

  exit();
}
Пример #2
0
int main(int argc, char** argv)
{
	char sh[200];
	strcpy(sh,"SHELL=");
	strcat(sh,getenv("PWD"));
	putenv(sh);

	if(argc==2)
	{
		//printf("file readin");
		if(freopen(argv[1],"r",stdin)==NULL){
			fprintf(stdout,"Failure to open");
		}
	}
	
	//char* comm;
	char str[200];
	char* commands[NUMBER_OF_COMMANDS]={"clr","dir","environ","quit","echo","cd","pause","help"};

	while(1)
	{
		//initializing redirection values
		in_=0;
		out_=0;
		app_=0;
		
		dont_wait=0; //sets next arguement to auto wait.
		fprintf(stdout,"%s==>",getenv("PWD"));
		fflush(stdout);
		//start reading function
		//get string and note that it has a newline character at the end of the string.
		
		if(fgets(str,200,stdin)==NULL)
		{
			fclose(stdin);
		}
		//end reading function
		strcpy(masterstr,str);
		
		//malloc buffer size
		int argcount=0;
		
		char* buffer =NULL;
		buffer=strtok(str," \n\t");
		char** argarray=(char**) malloc(sizeof(str));
		
		
		while(buffer!=NULL)
		{
			if(strcmp(buffer,"&")==0)
			{								
				fprintf(stdout,"%s",buffer);																														
				dont_wait=1;	
					
			}
			else if(strcmp(buffer,"<")==0)
			{
				fprintf(stdout,"%s",buffer);
				fprintf(stdin,"Input changed");	
				buffer=strtok(NULL," \n\t");
				if(buffer!=NULL)
				{
					strcpy(in,buffer);					
					in_=1;
				}
				
				
			}
			else if(strcmp(buffer,">")==0)
			{
				fprintf(stdout,"%s",buffer);
				fprintf(stdin,"Output changed");
				buffer=strtok(NULL," \n\t");
				if(buffer!=NULL)
				{
					strcpy(out,buffer);
					out_=1;
				}
			}
			else if(strcmp(buffer,">>")==0)
			{
				fprintf(stdout,"%s",buffer);
				fprintf(stdin,"append Out changed");
				buffer=strtok(NULL," \n\t");
				if(buffer!=NULL)
				{
					strcpy(app,buffer);
					app_=1;
				}
			}
			else
			{	
				argarray[argcount]=(char*) malloc(sizeof(buffer)); //allocate space for each argument 
				strcpy(argarray[argcount++],buffer);
				//take next value from command string
						
			}
			buffer=strtok(NULL," \n\t");
		}

		//start command parse
		int l;

		if(argarray[0]!=NULL)
		{
			for(l=0;l<NUMBER_OF_COMMANDS;l++)
			{
				//remove to test string comparison
				//fprintf(stdout,"%s:%s\n",arguments,commands[l]);
				if(strcmp(argarray[0],commands[l])==0)
				{
					break;
				}
		
			}
																																				
				//argarray[argcount++]=(char*) malloc (sizeof(str));											
				//argarray[argcount++]='\0';																									
				//remove to test the value of l																									
				//fprintf(stdout,"HELLO? %d",l);																									
																																									
				switch(l)																																	
				{																																					
					case(0):clr(argarray);break;																					
					case(1):dir(argarray,argcount);break;																		
					case(2):envi();break;
					case(3):return 0;break;
					case(4):echoarg(argarray,argcount);break;
					case(5):cd(argarray,argcount);break;
					case(6):sleeptime();break;
					case(7):help();break;
					default:other(argarray);break;
				}
			}
		
	}
}
Пример #3
0
/*
 * Main entry point:
 */
int MAIN(int argc, char **argv)
{
    // First print GPL information:
    printf("%s %s [%s] Copyright (C) 2017 basil\n", PROGRAM_NAME_LONG,
        PROGRAM_VERSION, PLATFORM);
    puts("License GPLv3+: GNU GPL version 3 or later "
        "<http://gnu.org/licenses/gpl.html>.");
    puts("This is free software: you are free to change and redistribute it.");
    puts("There is NO WARRANTY, to the extent permitted by law.");
    putchar('\n');

    // Process options:
    options_init(argc, argv);

    // Initialise various components (order is important!).
    log_init();
    trace("changing to home directory %s", PROGRAM_DIR);
    chdir_home();
    trace("installing files (if required)");
    install_files();
    trace("initialising user configuration");
    config_init();
    trace("initialising tunnel management");
    tunnel_init();

    // Initialise the sockets library (if required on this platform).
    trace("initialising sockets");
    init_sockets();

    // Get number of threads.
    int num_threads =
        (options_get()->seen_num_threads?  options_get()->val_num_threads:
            NUM_THREADS_DEFAULT);
    if (num_threads < 1 || num_threads > NUM_THREADS_MAX)
    {
        error("unable to spawn %d threads; expected a number within the "
            "range 1..%u", num_threads, NUM_THREADS_MAX);
    }

    // Create configuration server thread.
    trace("launching configuration server thread");
    if (thread_lock_init(&config_lock))
    {
        error("unable to initialise global configuration lock");
    }
    thread_t config_thread;
    if (!options_get()->seen_no_ui &&
        thread_create(&config_thread, configuration_thread, NULL) != 0)
    {
        error("unable to create configuration server thread");
    }

    // Open the packet capture/injection device driver.
    trace("initialising packet capture");
    if (!options_get()->seen_no_capture)
    {
        init_capture();
    }

    // Open the tunnels.
    trace("initialising tunnels");
    tunnel_file_read();
    tunnel_open();

    // Go to sleep if we are not capturing packets.
    while (options_get()->seen_no_capture)
    {
        sleeptime(UINT64_MAX);
    }

    // Start worker threads.
    for (int i = 1; i < num_threads; i++)
    {
        thread_t work_thread;
        if (thread_create(&work_thread, worker_thread, NULL) != 0)
        {
            error("unable to create worker thread");
        }
    }
    worker_thread((void *)0);

    return EXIT_SUCCESS;
}