Re: Problem with chrt

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Sep 26, 2010 at 3:22 PM, JD <jd1008@xxxxxxxxx> wrote:
> On 09/26/2010 10:04 AM, Tom H wrote:
>> On Sun, Sep 26, 2010 at 12:33 PM, JD<jd1008@xxxxxxxxx>  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!

You should be able to use pgrep in your script - and you probably
should launch it with "sudo ..." or "su -c ..." rather than include
two sudos in it.

I'd never used (or heard of) chrt before.

I've just tried "chrt 21 yum update" and it ran.

Also "chrt --help" offers different/better help than "man chrt".
-- 
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines



[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux