示例#1
0
文件: job.c 项目: 09zwcbupt/csapp
void print_all_job(void)
{
        int i;
        for (i = beg; i < end; i++) {
                if (!job[i])
                        continue;
                print_job(i);
                if (job[i]->state == JOB_DONE)
                        delete_job(job[i]->pgid);
        }
}
void list_jobs(job *jobs) {
	int i;
	char job_found = 0;
	for (i=0; i< MAXJOBS; i++) {
		if (jobs[i].pid != 0) {
			job_found = 1;
			print_job(jobs[i]);
		}
	}
	if(!job_found) printf("There isn't any job in this session\n");
}
void process_get(char *chunkfile, char *outputfile) {
    /* initilize the job */
    struct job_s* new_job = malloc_new_job(chunkfile, outputfile);
    if(new_job == NULL){
      /* failed to create a new job*/
      return;
    }
    current_job = new_job;
    print_job(current_job);

    flood_whohas();
}
void set_job_status(job *j, int status) {
	int fg_job = 0;
	if (j->state == FG) {
		fg_job = 1;
	}
	
	if (WIFSTOPPED(status)) {
		j->state = ST;
		print_job(*j);
	} else {
		j->state = TM;
		if (!fg_job)
			print_job(*j);
		
		initialize_job(j, j->jid);

		if(WIFSIGNALED(status)) {
			fprintf(stderr, "Terminated by signal %d.\n",
					 (int) j->pid, WTERMSIG(status));
		}
	}
}
示例#5
0
int main(int argc, char *argv[]){
	if(argc!=2){
		printf("usage: prog joblibst\n");	
		printf("Run jobs with definite num. of seconds since run useless\n");
		return EARG;
	}
	FILE *f;
	openf(f,argv[1],"r");
	int sec;
 	char * comm = NULL;
	size_t len = 0;
	while(fscanf(f,"%d ",&sec)==1){
		getline(&comm, &len, f);
		add_job(comm,sec);
	}
	fclose(f);
	qsort(jobs,cnt,sizeof(joblist),cmp); 
	print_job();
	exec_job();
	return SUCC;
}
示例#6
0
/*
 * Load all jobs and print information about each job
 */
void load_and_print_jobs (char * user) {

    int error_code = SLURM_SUCCESS, i;
    uint32_t array_id = NO_VAL;
    job_info_msg_t * job_buffer_ptr = NULL;
    job_info_t *job_ptr = NULL;
    char *end_ptr = NULL;

    error_code = (int) load_job(&job_buffer_ptr, 0);
    if (error_code) {
        slurm_perror ("slurm_load_jobs error");
        return;
    }

    printf("# jobid|jobstate|username|queue|requestedcores|mainnode|submittime|starttime\n");
    for (i = 0, job_ptr = job_buffer_ptr->job_array; i < job_buffer_ptr->record_count; i++, job_ptr++) {
        if ((array_id != NO_VAL) && (array_id != job_ptr->array_task_id)) {
            continue;
        }
        print_job(job_ptr, user);
    }
}
示例#7
0
void print_status(void){
    cout << "\n------Printing Status------\n";
    cout << "Current job: ";
    print_job(status.job);
    cout << endl;


    if(status.travel==AT_NODE)
        cout << "Currently: AT_NODE - node:" << status.current_node << endl;
    else
        cout << "Currently: IN_TRANSIT between nodes " << status.last_node << " and " << status.next_node << endl;
        
    cout << "Current direction: ";
    print_direction(status.direction);
    cout << endl;

    cout << "Front parcel is "; print_parcel_type(status.front_parcel);
    cout << "\nBack parcel is "; print_parcel_type(status.back_parcel);
    cout << "\nDelivered " << status.parcels_delivered << " parcels\n";
    cout << "\n---------------------------\n\n";
    return;
}
示例#8
0
文件: testlpd.c 项目: zdohnal/cups
int					/* O - Exit status */
main(int  argc,				/* I - Number of command-line arguments */
     char *argv[])			/* I - Command-line arguments */
{
  int	i;				/* Looping var */
  int	status;				/* Test status */
  char	*op,				/* Operation to test */
	**opargs,			/* Remaining arguments */
	*dest;				/* Destination */
  int	cupslpd_argc;			/* Argument count for cups-lpd */
  char	*cupslpd_argv[1000];		/* Arguments for cups-lpd */
  int	cupslpd_stdin[2],		/* Standard input for cups-lpd */
	cupslpd_stdout[2],		/* Standard output for cups-lpd */
	cupslpd_pid,			/* Process ID for cups-lpd */
	cupslpd_status;			/* Status of cups-lpd process */


 /*
  * Collect command-line arguments...
  */

  op              = NULL;
  opargs          = argv + argc;
  dest            = NULL;
  cupslpd_argc    = 1;
  cupslpd_argv[0] = (char *)"cups-lpd";

  for (i = 1; i < argc; i ++)
    if (!strncmp(argv[i], "-o", 2))
    {
      cupslpd_argv[cupslpd_argc++] = argv[i];

      if (!argv[i][2])
      {
        i ++;

	if (i >= argc)
	  usage();

	cupslpd_argv[cupslpd_argc++] = argv[i];
      }
    }
    else if (argv[i][0] == '-')
      usage();
    else if (!op)
      op = argv[i];
    else if (!dest)
      dest = argv[i];
    else
    {
      opargs = argv + i;
      break;
    }

  if (!op ||
      (!strcmp(op, "print-job") && (!dest || !opargs)) ||
      (!strcmp(op, "remove-job") && (!dest || !opargs)) ||
      (strcmp(op, "print-job") && strcmp(op, "print-waiting") &&
       strcmp(op, "remove-job") && strcmp(op, "status-long") &&
       strcmp(op, "status-short")))
  {
    printf("op=\"%s\", dest=\"%s\", opargs=%p\n", op, dest, opargs);
    usage();
  }

 /*
  * Run the cups-lpd program using pipes...
  */

  cupslpd_argv[cupslpd_argc] = NULL;

  pipe(cupslpd_stdin);
  pipe(cupslpd_stdout);

  if ((cupslpd_pid = fork()) < 0)
  {
   /*
    * Error!
    */

    perror("testlpd: Unable to fork");
    return (1);
  }
  else if (cupslpd_pid == 0)
  {
   /*
    * Child goes here...
    */

    dup2(cupslpd_stdin[0], 0);
    close(cupslpd_stdin[0]);
    close(cupslpd_stdin[1]);

    dup2(cupslpd_stdout[1], 1);
    close(cupslpd_stdout[0]);
    close(cupslpd_stdout[1]);

    execv("./cups-lpd", cupslpd_argv);

    perror("testlpd: Unable to exec ./cups-lpd");
    exit(errno);
  }
  else
  {
    close(cupslpd_stdin[0]);
    close(cupslpd_stdout[1]);
  }

 /*
  * Do the operation test...
  */

  if (!strcmp(op, "print-job"))
    status = print_job(cupslpd_stdin[1], cupslpd_stdout[0], dest, opargs);
  else if (!strcmp(op, "print-waiting"))
    status = print_waiting(cupslpd_stdin[1], cupslpd_stdout[0], dest);
  else if (!strcmp(op, "remove-job"))
    status = remove_job(cupslpd_stdin[1], cupslpd_stdout[0], dest, opargs);
  else if (!strcmp(op, "status-long"))
    status = status_long(cupslpd_stdin[1], cupslpd_stdout[0], dest, opargs);
  else if (!strcmp(op, "status-short"))
    status = status_short(cupslpd_stdin[1], cupslpd_stdout[0], dest, opargs);
  else
  {
    printf("Unknown operation \"%s\"!\n", op);
    status = 1;
  }

 /*
  * Kill the test program...
  */

  close(cupslpd_stdin[1]);
  close(cupslpd_stdout[0]);

  while (wait(&cupslpd_status) != cupslpd_pid);

  printf("cups-lpd exit status was %d...\n", cupslpd_status);

 /*
  * Return the test status...
  */

  return (status);
}
示例#9
0
int test_sieve(fact_obj_t* fobj, void* args, int njobs, int are_files)
/* if(are_files), then treat args as a char** list of (external) polys
 * else args is a nfs_job_t* array of job structs
 * the latter is preferred */
// @ben: the idea is a new yafu function "testsieve(n, ...)" where args are
// an arbitrary list of files of external polys
{
	uint32 count;
	int i, minscore_id = 0;
	double* score = (double*)malloc(njobs * sizeof(double));
	double t_time, min_score = 999999999.;
	char orig_name[GSTR_MAXSIZE]; // don't clobber fobj->nfs_obj.job_infile
	char time[80];
	uint32 spq_range = 2000, actual_range;
	FILE *flog;
	
	char** filenames; // args
	nfs_job_t* jobs; // args
	
	struct timeval stop, stop2;	// stop time of this job
	struct timeval start, start2;	// start time of this job
	TIME_DIFF *	difference;

	if( score == NULL )
	{
		printf("Couldn't alloc memory!\n");
		exit(-1);
	}

	// check to make sure we can find ggnfs sievers
	if (check_for_sievers(fobj, 0) == 1)
	{
		printf("test: can't find ggnfs lattice sievers - aborting test sieving\n");
		return -1;
	}

	gettimeofday(&start2, NULL);

	strcpy(orig_name, fobj->nfs_obj.job_infile);
	// necessary because parse/fill_job_file() get filename from fobj
	if( are_files )
	{ // read files into job structs (get fblim)

		filenames = (char**) args;
		jobs = (nfs_job_t*)malloc(njobs * sizeof(nfs_job_t));
		if( jobs == NULL )
		{
			printf("Couldn't alloc memory!\n");
			exit(-1);
		}
		memset(jobs, 0, njobs*sizeof(nfs_job_t));

		for(i = 0; i < njobs; i++)
		{
			uint32 missing_params;
			strcpy(fobj->nfs_obj.job_infile, filenames[i]);

			missing_params = parse_job_file(fobj, jobs+i); // get fblim
			get_ggnfs_params(fobj, jobs+i); // get siever
			if( missing_params )
			{
				if( VFLAG >= 0 )
					printf("test: warning: \"%s\" is missing some paramters (%#X). filling them.\n",
						filenames[i], missing_params);
				fill_job_file(fobj, jobs+i, missing_params);
			}
			// adjust a/rlim, lpbr/a, and mfbr/a if advantageous
			skew_snfs_params(fobj, jobs+i);
		}
	}
	else
	{ // create poly files
		jobs = (nfs_job_t *) args;
		filenames = (char**)malloc(njobs*sizeof(char*));
		if( !filenames )
		{
			printf("malloc derped it up!\n");
			exit(-1);
		}
		for(i = 0; i < njobs; i++)
		{
			FILE* out;
			filenames[i] = (char*)malloc(GSTR_MAXSIZE);
			if( !filenames[i] )
			{
				printf("malloc failed\n");
				exit(-1);
			}
			sprintf(filenames[i], "test-sieve-%d.poly", i);
			out = fopen(filenames[i], "w");
			if( !out )
			{
				printf("test: couldn't open %s for writing, aborting test sieve\n", filenames[i]);
				return -1;
			}
			if( jobs[i].snfs )
				print_snfs(jobs[i].snfs, out);
			else
			{
				gmp_fprintf(out, "n: %Zd\n", fobj->nfs_obj.gmp_n);
				print_poly(jobs[i].poly, out);
			}
			fclose(out);
			strcpy(fobj->nfs_obj.job_infile, filenames[i]);
			fill_job_file(fobj, jobs+i, PARAM_FLAG_ALL);
		} 
		// that seems like a lot more code than it should be
	}
	strcpy(fobj->nfs_obj.job_infile, orig_name);

	// now we can get to the actual testing
	for(i = 0; i < njobs; i++)
	{
		char syscmd[GSTR_MAXSIZE], tmpbuf[GSTR_MAXSIZE], side[32];
		FILE* in;

		// should probably scale the range of special-q to test based
		// on input difficulty, but not sure how to do that easily...

		if( jobs[i].poly->side == RATIONAL_SPQ)
		{
			sprintf(side, "rational");
			jobs[i].startq = jobs[i].rlim; // no reason to test sieve *inside* the fb
		}
		else
		{
			sprintf(side, "algebraic");
			jobs[i].startq = jobs[i].alim; // ditto
		}

		flog = fopen(fobj->flogname, "a");

		//create the afb/rfb - we don't want the time it takes to do this to
		//pollute the sieve timings		
		sprintf(syscmd, "%s -b %s -k -c 0 -F", jobs[i].sievername, filenames[i]);
		if (VFLAG > 0) printf("\ntest: generating factor bases\n");
		gettimeofday(&start, NULL);
		system(syscmd);
		gettimeofday(&stop, NULL);
		difference = my_difftime (&start, &stop);
		t_time = ((double)difference->secs + (double)difference->usecs / 1000000);
		free(difference);
		if (VFLAG > 0) printf("test: fb generation took %6.4f seconds\n", t_time);
		logprint(flog, "test: fb generation took %6.4f seconds\n", t_time);
		MySleep(.1);

		//start the test
		sprintf(syscmd,"%s%s -%c %s -f %u -c %u -o %s.out",
			jobs[i].sievername, VFLAG>0?" -v":"", side[0], filenames[i], jobs[i].startq, spq_range, filenames[i]);

		if (VFLAG > 0) printf("test: commencing test sieving of polynomial %d on the %s side over range %u-%u\n", i, 
			side, jobs[i].startq, jobs[i].startq + spq_range);
		logprint(flog, "test: commencing test sieving of polynomial %d on the %s side over range %u-%u\n", i, 
			side, jobs[i].startq, jobs[i].startq + spq_range);
		print_job(&jobs[i], flog);
		fclose(flog);

		gettimeofday(&start, NULL);
		system(syscmd);
		gettimeofday(&stop, NULL);
		difference = my_difftime (&start, &stop);
		t_time = ((double)difference->secs + (double)difference->usecs / 1000000);
		free(difference);		
		
		//count relations
		sprintf(tmpbuf, "%s.out", filenames[i]);
		in = fopen(tmpbuf, "r");
		actual_range = 0;
		count = 0;
		if( !in )
		{
			score[i] = 999999999.;
			
			//est = 7*365*24*3600; // 7 years seems like a nice round number
		}
		else
		{
			// scan the data file and
			// 1) count the relations
			// 2) save the last four relations to a buffer in order to extract the last processed
			//		special-q.
			// we need both 1) and 2) to compute yield correctly.

			char **lines, *ptr, tmp[GSTR_MAXSIZE];
			int line;
			int j;

			lines = (char **)malloc(4 * sizeof(char *));
			for (j=0; j < 4; j++)
				lines[j] = (char *)malloc(GSTR_MAXSIZE * sizeof(char));

			line = 0;
			count = 0;
			while (1)
			{
				// read a line into the next position of the circular buffer
				ptr = fgets(tmp, GSTR_MAXSIZE, in);
				if (ptr == NULL) 
					break;

				// quick check that it might be a valid line
				if (strlen(tmp) > 30)
				{
					// wrap
					if (++line > 3) line = 0;
					// then copy
					strcpy(lines[line], tmp);
				}

				count++;
			}
			fclose(in);

			line = get_spq(lines, line, fobj);
			actual_range = line - jobs[i].startq;
			if (VFLAG > 0)
				printf("test: found %u relations in a range of %u special-q\n", 
				count, actual_range);

			if (actual_range > spq_range) 
				actual_range = spq_range;

			for (j=0; j < 4; j++)
				free(lines[j]);
			free(lines);

			score[i] = t_time / count;

			// use estimated sieving time to rank, not sec/rel, since the latter
			// is a function of parameterization and therefore not directly comparable
			// to each other.
			score[i] = (score[i] * jobs[i].min_rels * 1.25) / THREADS; 
			// be conservative about estimates
		}

		flog = fopen(fobj->flogname, "a");

		if( score[i] < min_score )
		{
			minscore_id = i;
			min_score = score[i];
			if (VFLAG > 0) printf("test: new best estimated total sieving time = %s (with %d threads)\n", 
				time_from_secs(time, (unsigned long)score[i]), THREADS); 
			logprint(flog, "test: new best estimated total sieving time = %s (with %d threads)\n", 
				time_from_secs(time, (unsigned long)score[i]), THREADS); 

			// edit lbpr/a depending on test results.  we target something around 2 rels/Q.
			// could also change siever version in more extreme cases.
			if (count > 4*actual_range)
			{
				if (VFLAG > 0)
					printf("test: yield greater than 4x/spq, reducing lpbr/lpba\n");
				jobs[i].lpba--;
				jobs[i].lpbr--;
				jobs[i].mfba -= 2;
				jobs[i].mfbr -= 2;
			}

			if (count > 8*actual_range)
			{
				char *pos;
				int siever;

				pos = strstr(jobs[i].sievername, "gnfs-lasieve4I");
				siever = (pos[14] - 48) * 10 + (pos[15] - 48);

				if (VFLAG > 0)
					printf("test: yield greater than 8x/spq, reducing siever version\n");

				switch (siever)
				{
				case 11:
					if (VFLAG > 0) printf("test: siever version cannot be decreased further\n");
					jobs[i].snfs->siever = 11;
					break;

				case 12:
					pos[15] = '1';
					jobs[i].snfs->siever = 11;
					break;

				case 13:
					pos[15] = '2';
					jobs[i].snfs->siever = 12;
					break;

				case 14:
					pos[15] = '3';
					jobs[i].snfs->siever = 13;
					break;

				case 15:
					pos[15] = '4';
					jobs[i].snfs->siever = 14;
					break;

				case 16:
					pos[15] = '5';
					jobs[i].snfs->siever = 15;
					break;
				}
			}

			if (count < actual_range)
			{
				if (VFLAG > 0)
					printf("test: yield less than 1x/spq, increasing lpbr/lpba\n");
				
				jobs[i].lpba++;
				jobs[i].lpbr++;
				jobs[i].mfba += 2;
				jobs[i].mfbr += 2;
			}

			if (count < (actual_range/2))
			{
				char *pos;
				int siever;

				pos = strstr(jobs[i].sievername, "gnfs-lasieve4I");
				siever = (pos[14] - 48) * 10 + (pos[15] - 48);

				if (VFLAG > 0)
					printf("test: yield less than 1x/2*spq, increasing siever version\n");

				switch (siever)
				{
				case 16:
					if (VFLAG > 0) printf("test: siever version cannot be increased further\n");
					jobs[i].snfs->siever = 16;
					break;

				case 15:
					pos[15] = '6';
					jobs[i].snfs->siever = 16;
					break;

				case 14:
					pos[15] = '5';
					jobs[i].snfs->siever = 15;
					break;

				case 13:
					pos[15] = '4';
					jobs[i].snfs->siever = 14;
					break;

				case 12:
					pos[15] = '3';
					jobs[i].snfs->siever = 13;
					break;

				case 11:
					pos[15] = '2';
					jobs[i].snfs->siever = 12;
					break;
				}
			}
     	}
		else
		{
			if (VFLAG > 0) printf("test: estimated total sieving time = %s (with %d threads)\n", 
				time_from_secs(time, (unsigned long)score[i]), THREADS);
			logprint(flog, "test: estimated total sieving time = %s (with %d threads)\n", 
				time_from_secs(time, (unsigned long)score[i]), THREADS);
		}

		fclose(flog);
		remove(tmpbuf); // clean up after ourselves
		sprintf(tmpbuf, "%s", filenames[i]);
		remove(tmpbuf);
		sprintf(tmpbuf, "%s.afb.0", filenames[i]);
		remove(tmpbuf);
	}

	// clean up memory allocated
	if( are_files )
	{
		for(i = 0; i < njobs; i++)
		{
			mpz_polys_free(jobs[i].poly);
			free(jobs[i].poly);
		}
		free(jobs);
	}
	else
	{
		for(i = 0; i < njobs; i++)
			free(filenames[i]);
		free(filenames);
	}

	flog = fopen(fobj->flogname, "a");
	gettimeofday(&stop2, NULL);
	difference = my_difftime (&start2, &stop2);
	t_time = ((double)difference->secs + (double)difference->usecs / 1000000);
	free(difference);			
	if (VFLAG > 0) printf("test: test sieving took %1.2f seconds\n", t_time);
	logprint(flog, "test: test sieving took %1.2f seconds\n", t_time);

	return minscore_id;
}
示例#10
0
文件: job.c 项目: 09zwcbupt/csapp
void print_job_by_pgid(pid_t pgid)
{
        int jid = find_job(pgid);
        print_job(jid);
}