Messages in this thread | | | Subject | Re: sched_setscheduler() and usage issues ....please help | From | Steven Rostedt <> | Date | Mon, 28 Mar 2005 23:40:15 -0500 |
| |
On Tue, 2005-03-29 at 08:58 +0530, Arun Srinivas wrote: > I am trying to set the SCHED_FIFO policy for my process.I am using > sched_setscheduler() function to do this.
Attached is a little program that I use to set the priority of tasks.
-- Steve /* Copyright (C) 2004 Kihon Technologies Inc.
This utilities is free software, you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
These utilities are distributed in the hope that they will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with the GNU C Library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ /* * Author: Steven Rostedt */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sched.h> #include <strutils.h> #include <errno.h>
void usage (char **argv) { char *arg = argv[0]; char *p = arg + strlen(arg); while (p >= arg && *p != '/') p--; p++; fprintf(stderr,"usage: %s pid policy priority\n" "\n\twhere policy is SCHED_RR, SCHED_FIFO or SCHED_OTHER\n" "\n", p); exit(-1); }
int main (int argc, char **argv) { pid_t pid; int policy; struct sched_param p; char *strpolicy; if (argc != 4) usage(argv);
strpolicy = argv[2]; pid = atoi(argv[1]); p.sched_priority = atoi(argv[3]);
if (strcmp(strpolicy,"SCHED_RR")==0) { policy = SCHED_RR; } else if (strcmp(strpolicy,"SCHED_FIFO") == 0) { policy = SCHED_FIFO; } else if (strcmp(strpolicy,"SCHED_OTHER") == 0) { policy = SCHED_OTHER; } else { fprintf(stderr,"\nunknown policy %s",strpolicy); usage(argv); }
if (sched_setscheduler(pid,policy,&p)) { perror("sched_setscheduler"); exit(errno); } exit(0); }
| |