/* * Project: * Explore the POSIX1003.1b Scheduling Interface. * * Author: * (c) Till Christian Siering. * * File: * atprio1.c * * Description: * Runs a given Program with a given Priority using * Scheduling-Fifo Scheduling. * * Begin: * I don't remember. * * Changes: * 22.07.1997 added Comments. * * To do: * Probably the Scheduling Algorithm could be a Option, too. * * References: * Bill O. Gallmeister: POSIX.4, O'Reilly & Associates Inc. */ #include #include #include char *progname; void usage() { fprintf(stderr,"Usage %s \n", progname); } int main(int argc, char **argv) { int priority; int min_priority; int max_priority; struct sched_param cmd_sched_params; progname = argv[0]; if(argc < 3) { usage(); exit(1); } priority = atoi(argv[1]); if((min_priority = sched_get_priority_min(SCHED_FIFO)) == -1) { perror("sched_get_priority_min"); exit(2); } if((max_priority = sched_get_priority_max(SCHED_FIFO)) == -1) { perror("sched_get_priority_max"); exit(2); } if((priority < min_priority) || (priority > max_priority )) { fprintf(stderr,"Priority must be greater or equal %d and smaller or equal %d\n", min_priority, max_priority); exit(2); } cmd_sched_params.sched_priority = priority; /* * Set Scheduling-Fifo for this Process. */ if(sched_setscheduler(0, SCHED_FIFO, &cmd_sched_params) < 0) { perror("sched_setscheduler"); exit(2); } /* * Execute Command. */ if(execvp(argv[2], &argv[2]) < 0) { perror("execvp"); exit(3); } }