Пример #1
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);
	}
}
Пример #2
0
Файл: test3.c Проект: 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
}