Problem with chrt
JD
jd1008 at gmail.com
Sun Sep 26 19:22:21 UTC 2010
On 09/26/2010 10:04 AM, Tom H wrote:
> On Sun, Sep 26, 2010 at 12:33 PM, JD<jd1008 at gmail.com> wrote:
>> I am trying to run a command in realtime mode just to see
>> if it behaves any different as far as timings are concerned.
>>
>> Man page says:
>>
>> chrt - manipulate real-time attributes of a process
>>
>> chrt [options] prio command [arg]...
>> chrt [options] -p [prio] pid
>>
>> So, I tried the first example instance above:
>>
>> $ sudo chrt 0 ./freq -s120 -u0 -r
>> chrt: failed to set pid 0's policy: Invalid argument
>>
>> Soo I tried:
>>
>> $ sudo chrt ./freq -s120 -u0 -r # i.e. no value for priority
>> chrt: failed to set pid 0's policy: Invalid argument
> You probably have to enclose "./freq..." in single or double quotes.
$ sudo chrt 0 "./freq -s120 -u0 -r"
chrt: failed to set pid 0's policy: Invalid argument
$ sudo chrt 0 './freq -s120 -u0 -r'
chrt: failed to set pid 0's policy: Invalid argument
Obviously chrt is busted as far as having a command as one of it's
args is concerned.
Or so I thought....
Then I decided to use the second form of the command where a PID is
sspecified,
ala
chrt [options] -p [prio] PID
The man page says that the option -f sets the scheduling type to FIFO.
So I concocted a way to do that by this script:
#!/bin/sh
sudo nice --60 ./freq -s120 -u0 -r &
ps -ef | grep freq | egrep -v 'grep|sudo' | awk '{ print $2 }' | xargs
sudo chrt -f -p 0
When I ran it, I got:
[1] 11340 <<<<< This is the pid of the sudo, and not of ./freq
pid 11348's current scheduling policy: SCHED_OTHER
pid 11348's current scheduling priority: 0
So, the gist of this is that I requested a FIFO scheduling policy by
the -f option to chrt.
Yet, chrt decided to use SCHED_OTHER.
So, I downloaded the source rpm (util-linux-ng)
and looked at the file chrt.c
The joke is, it does not even parse it's args for the command the user
wants to run.
So, the man page ought to dump the first form of invoking chrt; namely
chrt [options] prio command [arg]...
'cause it is not even being looked for in the args.
To wit (from soource code):
while((i = getopt_long(argc, argv, "+bfiphmorvV", longopts,
NULL)) != -1)
{
int ret = EXIT_FAILURE;
switch (i) {
case 'b':
#ifdef SCHED_BATCH
policy = SCHED_BATCH;
#endif
break;
case 'f':
policy = SCHED_FIFO;
break;
case 'i':
#ifdef SCHED_IDLE
policy = SCHED_IDLE;
#endif
break;
case 'm':
show_min_max();
return 0;
case 'o':
policy = SCHED_OTHER;
break;
case 'p':
errno = 0;
pid = strtol(argv[argc - 1], NULL, 10);
if (errno)
err(EXIT_FAILURE, _("failed to parse
pid"));
break;
case 'r':
policy = SCHED_RR;
break;
case 'v':
verbose = 1;
break;
case 'V':
printf("chrt (%s)\n", PACKAGE_STRING);
return 0;
case 'h':
ret = EXIT_SUCCESS;
default:
show_usage(ret);
}
}
if (((pid > -1) && argc - optind < 1) || ((pid == -1) && argc -
optind < 2))
show_usage(EXIT_FAILURE);
The if condition always succeeds whether or not you embed the command
argument and it's args in single or double quotes.
In fact it never scans of the user command!
More information about the users
mailing list