int main( void ) { prio_t prio1, prio2; int i, j; pid_t pid; pid = getpid(); prio1 = getprio(); c_printf( "User T (%d) running, initial prio %d\n", pid, prio1 ); writech( 'T' ); for( i = 0; i < 20; ++i ) { for( j = 0; j < DELAY_STD; ++j ) continue; writech( 'T' ); } prio2 = setprio( PRIO_HIGH ); prio1 = getprio(); c_printf( "User T, set prio #1 old %d new %d\n", prio2, prio1 ); writech( 'T' ); for( i = 0; i < 20; ++i ) { for( j = 0; j < DELAY_STD; ++j ) continue; writech( 'T' ); } prio2 = setprio( PRIO_LOW ); prio1 = getprio(); c_printf( "User T, set prio #2 old %d new %d\n", prio2, prio1 ); writech( 'T' ); for( i = 0; i < 20; ++i ) { for( j = 0; j < DELAY_STD; ++j ) continue; writech( 'T' ); } prio2 = setprio( PRIO_STD ); prio1 = getprio(); c_printf( "User T, set prio #3 old %d new %d\n", prio2, prio1 ); writech( 'T' ); for( i = 0; i < 30; ++i ) { for( j = 0; j < DELAY_STD; ++j ) continue; writech( 'T' ); } c_puts( "User T exiting\n" ); exit(); }
/*------------------------------------------------------------------------ * ready - Make a process eligible for CPU service *------------------------------------------------------------------------ */ status ready( pid32 pid /* ID of process to make ready */ ) { register struct procent *prptr; if (isbadpid(pid)) { return SYSERR; } /* Set process state to indicate ready and add to ready list */ prptr = &proctab[pid]; record_cpuqdata(pid); /* call function to record process state time data */ /* (actual recording is controlled by EV_CPUQDATA env var and choice of scheduler) */ prptr->prstate = PR_READY; readycount++; /* increase the readylist count tracker */ /* assigns a new adjusted priority based on the scheduler currently active */ prptr->prprio = setprio(pid); insert(pid, readylist, prptr->prprio); resched(); return OK; }
static int perform_flag_actions(spawn_attr_t *sap) { int sig; struct sigaction action; if (sap->sa_psflags & POSIX_SPAWN_SETSIGMASK) { (void) __lwp_sigmask(SIG_SETMASK, &sap->sa_sigmask); } if (sap->sa_psflags & POSIX_SPAWN_SETSIGIGN_NP) { (void) memset(&action, 0, sizeof (action)); action.sa_handler = SIG_IGN; for (sig = 1; sig < NSIG; sig++) { if (sigismember(&sap->sa_sigignore, sig)) (void) __sigaction(sig, &action, NULL); } } if (sap->sa_psflags & POSIX_SPAWN_SETSIGDEF) { (void) memset(&action, 0, sizeof (action)); action.sa_handler = SIG_DFL; for (sig = 1; sig < NSIG; sig++) { if (sigismember(&sap->sa_sigdefault, sig)) (void) __sigaction(sig, &action, NULL); } } if (sap->sa_psflags & POSIX_SPAWN_RESETIDS) { if (setgid(getgid()) != 0 || setuid(getuid()) != 0) return (errno); } if (sap->sa_psflags & POSIX_SPAWN_SETPGROUP) { if (setpgid(0, sap->sa_pgroup) != 0) return (errno); } if (sap->sa_psflags & POSIX_SPAWN_SETSCHEDULER) { if (setparam(P_LWPID, P_MYID, sap->sa_schedpolicy, sap->sa_priority) == -1) return (errno); } else if (sap->sa_psflags & POSIX_SPAWN_SETSCHEDPARAM) { if (setprio(P_LWPID, P_MYID, sap->sa_priority, NULL) == -1) return (errno); } return (0); }
int main(int argc, char *argv[]) { int processes_count = argc - 2; char strategy[10]; strcpy(strategy, argv[argc-1]); int s_strategy; if (strcmp(strategy, "FIFO") == 0) { s_strategy = SCHED_FIFO; } else if(strcmp(strategy, "RR") == 0) { s_strategy = SCHED_RR; } else { s_strategy = SCHED_SPORADIC; } struct sched_param par; int str; sched_getparam(0, &par); sched_setscheduler(0, s_strategy, &par); str = sched_getscheduler(0); printf("Strategia szeregowania: %d\n", str); sleep(5); int i; for(i = 0; i < processes_count; i++) { int pid = fork(); if (pid == 0) { int priority = atoi(argv[i+1]); setprio(getpid(), priority); int j = 0; long long x; while (j < 21474836) { x = j * j; printf("Proces numer: %d\n", i); } break; } } int pid; int status; while((pid=wait(&status))!=-1) printf("Proces %d zakonczony, status %d\n",pid,WEXITSTATUS(status)); return (0); }
/* The thread to start */ static void *my_rt_thread(void *args) { struct timespec ts; ts.tv_sec = 30; ts.tv_nsec = 0; setprio(sched_get_priority_max(SCHED_RR), SCHED_RR); printf("I am an RT-thread with a stack that does not generate " \ "page-faults during use, stacksize=%i\n", MY_STACK_SIZE); //<do your RT-thing here> show_new_pagefault_count("Caused by creating thread", ">=0", ">=0"); prove_thread_stack_use_is_safe(MY_STACK_SIZE); /* wait 30 seconds before thread terminates */ clock_nanosleep(CLOCK_REALTIME, 0, &ts, NULL); return NULL; }
int main( int argc, char *argv[] ) { dl_head_typ *pusr; /* A list of slv_clt_typ structures, * which contain client information, * and channels for communications. */ slv_db_typ *pdb; /* The variable list, which contains * data, the sizes, and a list trigger * clients for each variable. */ comm_clt_typ *psvc_clt; /* Client calls are received here. */ comm_clt_typ *pdb_clt; /* This points to the current client.*/ db_data_typ recv_buff; /* The buffer of information from the * client. */ char *pservname; /* The service name to be supported.*/ int option; int priority; int name_id; void *name_struct; int xport = COMM_PSX_XPORT; // transport mechanism int handle = COMM_WILD_HANDLE; // for COMM_QNX_XPORT, receive all /* Set to invalid values to facilitate error exits. */ pdb = NULL; psvc_clt = NULL; pusr = NULL; name_id = ERROR; name_struct = NULL; verbose_flag = FALSE; pservname = DEFAULT_SERVICE; while( (option = getopt( argc, argv, "S:P:qQv?" )) != EOF ) { switch( option ) { case 'v': verbose_flag = TRUE; break; case 'P': priority = atoi( optarg ); if( setprio( 0, priority ) == ERROR ) { fprintf(stderr, "Can't change priority to %d\n", priority ); exit( EXIT_FAILURE ); } break; case 'S': pservname = optarg; break; case 'q': xport = COMM_QNX_XPORT; break; case 'Q': xport = COMM_QNX6_XPORT; break; case '?': default: usage( argv[0] ); exit( EXIT_FAILURE ); break; } } if (verbose_flag) { printf("Starting PATH DB data server\n"); fflush(stdout); } if ( !slv_db_publish_name (xport, pservname, &name_id, &name_struct) ) { fprintf( stderr, "Can't publish service %s\n", pservname); slv_done( pdb, pusr, psvc_clt, name_id, pservname, name_struct); exit( EXIT_FAILURE ); } /* Beware that name_id is now the channel id in QNX 6, so * don't want to pass in COMM_WILD_HANDLE. But code for QNX 4 * assumes COMM_WILD_HANDLE, so must special case this */ if ( COMM_QNX6_XPORT == xport ) { handle = comm_get_handle( xport, pservname, name_id ); } else { handle = comm_get_handle( xport, pservname, COMM_WILD_HANDLE ); } if( (pdb = slv_db_create()) == NULL ) { fprintf( stderr, "%s: Can't create database\n", argv[0] ); slv_done( pdb, pusr, psvc_clt, name_id, pservname, name_struct ); exit( EXIT_FAILURE ); } else if( (psvc_clt = comm_init( xport, handle )) == NULL ) { fprintf( stderr, "%s: Can't create server communications\n", argv[0] ); slv_done( pdb, pusr, psvc_clt, name_id, pservname, name_struct ); exit( EXIT_FAILURE ); } else if( (pusr = dl_create()) == NULL ) { fprintf( stderr, "%s: Can't create usr list\n", argv[0] ); slv_done( pdb, pusr, psvc_clt, name_id, pservname, name_struct ); exit( EXIT_FAILURE ); } else if( setjmp( exit_env ) != 0 ) { slv_done( pdb, pusr, psvc_clt, name_id, pservname, name_struct ); exit( EXIT_SUCCESS ); } else sig_ign( sig_list, sig_hand ); if (verbose_flag) { printf("db slv: pdb 0x%x pusr 0x%x\n", (unsigned int) pdb, (unsigned int) pusr); } while( (pdb_clt = comm_sync_recv( psvc_clt, &recv_buff, DB_COMM_SIZE )) != NULL ) { if( verbose_flag == TRUE ) db_print( &recv_buff ); if( (slv_cmd( pdb, pusr, pdb_clt, &recv_buff ) == FALSE) && (verbose_flag == TRUE) ) { printf( "%s: processing failed.\n", argv[0] ); db_print( &recv_buff ); } } longjmp( exit_env, EXIT_FAILURE ); }