Example #1
0
void init_fn()
{
	int j;
	for (j = 0; j < 2; j++)
	{
	 	switch(sched_fork())
	 	{
	 		case -1:
	 			fprintf(stderr, "fork error!\n");
	 			exit(1);
	 		case 0:
	 			if (!j)
	 			{
	 				sched_nice(-20);
	 				child1();
	 			}
	 			else
	 			{
	 				sched_nice(20);
	 				child2();
	 			}
	 			
	 			exit(0);
	 	}
	}
	//sched_nice(5);
 	parent();
 	exit(0);
 }
Example #2
0
void init() {
	signal(SIGUSR1, &signal1);
	printf("[Init][Pid: %d] Scheduler Testing Program\n", sched_getpid());
	sched_nice(-20);
	for (int i = 0; i < 15; i++) {
		if (sched_fork() == 0) {
			printf("[Child][Pid: %d] Parent Pid: %d\n", sched_getpid(), sched_getppid());
			sched_nice(-19 + i);
			struct timespec start, stop;
			clock_gettime(CLOCK_REALTIME, &start);
			for (long int j = 0; j < 1000000000; j++);
			clock_gettime(CLOCK_REALTIME, &stop);
			printf("[Child][Pid: %d] Execution Complete. Took %ld Seconds.\n", sched_getpid(), (long int)(stop.tv_sec - start.tv_sec));
			sched_exit(i);
			printf("[Child][Pid: %d] This Will Never Get Executed\n", sched_getpid());
		}
	}
	printf("[Init][Pid: %d] Process Information\n", sched_getpid());
	sched_ps();
	for (int i = 0; i < 15; i++) {
		int returncode;
		int cc = sched_wait(&returncode);
		printf("[Init][Pid: %d] Child Returned [%d] With Exit Code [%d]\n", sched_getpid(), cc, returncode);
	}
	int returncode;
	int cc = sched_wait(&returncode);
	printf("[Init][Pid: %d] Calling Wait With No Children Returns [%d]\n", sched_getpid(), cc);
	sched_sleep(&wait1);
	for (int i = 0; i < 15; i++) {
		if (sched_fork() == 0) {
			printf("[Child][Pid: %d] Parent Pid: %d\n", sched_getpid(), sched_getppid());
			sched_nice(-19 + i);
			if (i % 2 == 1)
				sched_sleep(&wait1);
			else
				sched_sleep(&wait2);
			printf("[Child][Pid: %d] Execution Complete.\n", sched_getpid());
			sched_exit(i);
		}
	}
	for (int i = 0; i < 1000000000; i++);
	printf("[Init][Pid: %d] Process Information\n", sched_getpid());
	sched_ps();
	printf("Wakeup 2\n");
	sched_wakeup(&wait2);
	printf("Wakeup 1\n");
	sched_wakeup(&wait1);
	for (int i = 0; i < 15; i++) {
		int returncode;
		int cc = sched_wait(&returncode);
		printf("[Init][Pid: %d] Child Returned [%d] With Exit Code [%d]\n", sched_getpid(), cc, returncode);
	}
	printf("[Init][Pid: %d] Exiting Testing Program. Passing Control Back To Idle\n", sched_getpid());
	sched_exit(0);
}
Example #3
0
init_fn() {
	int i, j, stat;
	printf("Created init function: ");
	printf("pid %d / niceval: %d\n",current->pid, current->stat_prio);
	sched_waitq_init(&wq1);
	sched_waitq_init(&wq2);
	
	// Parent process forks 9 CPU-bound processes
	for (i=1; i<10; i++) {
		switch(sched_fork()) {
		case -1: 
			fprintf(stderr,"Fork failed in pid %d\n",current->pid);
			return -1;
			break;
		case 0:
			sched_nice(20+i*2);
			child_fn();
			sched_exit(0);
			break;
		}
	}
	// Parent process waits for a long time before it 
	//	does its own CPU-bound operations
	kill(getpid(),SIGABRT);
	for (;;) {
		for (i=0; i<40; i++)
			sched_sleep(&wq1);
		kill(getpid(),SIGABRT);
		waste_time(10);
		kill(getpid(),SIGABRT);
	}
}
int do_getsetpriority()
 {
         int r, arg_which, arg_who, arg_pri;
         struct mproc *rmp;

         arg_which = m_in.m_lc_pm_priority.which;
         arg_who = m_in.m_lc_pm_priority.who;
         arg_pri = 1   /* for SETPRIORITY we set highest priority */

         /* Code common to GETPRIORITY and SETPRIORITY. */

         /* Only support PRIO_PROCESS for now. */
         if (arg_which != PRIO_PROCESS)
                 return(EINVAL);

         if (arg_who == 0)
                rmp = mp;
         else
                 if ((rmp = find_proc(arg_who)) == NULL)
                         return(ESRCH);

         if (mp->mp_effuid != SUPER_USER &&
            mp->mp_effuid != rmp->mp_effuid && mp->mp_effuid != rmp->mp_realuid)
                 return EPERM;

         /* If GET, that's it. */
         if (call_nr == PM_GETPRIORITY) {
                 return(rmp->mp_nice - PRIO_MIN);
         }

         /* Only root is allowed to reduce the nice level. */
         if (rmp->mp_nice > arg_pri && mp->mp_effuid != SUPER_USER)
                 return(EACCES);

         /* We're SET, and it's allowed.
          *
          * The value passed in is currently between PRIO_MIN and PRIO_MAX.
          * We have to scale this between MIN_USER_Q and MAX_USER_Q to match
          * the kernel's scheduling queues.
          */

         if ((r = sched_nice(rmp, arg_pri)) != OK) {
                 return r;
         }

         rmp->mp_nice = arg_pri;
         return(OK);
}
Example #5
0
File: test3.c Project: mbryk/OS
init_fn(){
	int i,p;
	time_t t = time(0);
	for(i=0;i<SCHED_NPROC-1;i++){
		p=sched_fork();
		if(p<0){ fprintf(stderr,"fork #%d failed\n",i); exit(-1); }
		else if(!p){ sched_nice((i%40)-20); break; }
	}
	int x;
	for(x=1;x<1<<DELAY_FACTOR;x++)
		;
	if(current->pid==1){
		kill(getpid(),SIGABRT);
	} else {
		sched_exit(0);
	}
	struct sched_waitq wq1;
	sched_waitq_init(&wq1);
	sched_sleep(&wq1); // Sleep Indefinitely
}
void test_fn() {
  
    fprintf(stdout, "Successfully made it to the testing function\n");

    int i;
    for (i = -2; i < 2; i += 1) {
        switch(sched_fork()) {
            case -1:
                fprintf(stderr, "Error: fork failed.\n");
                exit(1);

            case 0:
                sched_nice(i);
                child();
                exit(1);
        }
    }

    parent();
    exit(0);
}