Home > Archive > PERL Miscellaneous > August 2007 > FAQ 8.39 How do I set CPU limits?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
FAQ 8.39 How do I set CPU limits?
|
|
| PerlFAQ Server 2007-08-21, 7:04 pm |
| This is an excerpt from the latest version perlfaq8.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .
--------------------------------------------------------------------
8.39: How do I set CPU limits?
Use the BSD::Resource module from CPAN.
--------------------------------------------------------------------
The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.
If you'd like to help maintain the perlfaq, see the details in
perlfaq.pod.
--
Posted via a free Usenet account from http://www.teranews.com
| |
| Michele Dondi 2007-08-22, 4:10 am |
| On Tue, 21 Aug 2007 15:34:26 -0700, Bill H <bill@ts1000.us> wrote:
>Could we get a little more detail in these? A cursory (and I do mean
>cursory) look at BSD::Resourse on CPAN gives details on how to
>implement it but really doesnt explain upfront what it will actually
>do. Does it set how much CPU time a program can use, or a percentage
>of usage, or a time period before it will be stopped?
>
>This post is not ment to be a complaint or cause anyone to get upset,
>I just think, since they are aimed at the "newbies" and those like me
>who want to learn more a little more "english" in them would make it
>more helpful.
Just to understand: do you find this to be a charachteristic of this
specific FAQ entry, and possibly of some other, or a general one of
the FAQ. If the former, I *think* that the limits are somewhat
intrinsic of the subject. I *think* that there may be now some other
OS specific modules e.g. in a Linux::* namespace to do similar things,
and so on.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{po
p^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
| |
| brian d foy 2007-08-22, 7:04 pm |
| In article <1187735666.719070.239920@e9g2000prf.googlegroups.com>, Bill
H <bill@ts1000.us> wrote:
> I like these perl faq postings and have learned a lot from them, but
> is it possible to get more details in them? For instance this one.
> This is a very interesting subject:
>
> 8.39: How do I set CPU limits?
>
> But it only gives a one line answer:
>
> Use the BSD::Resource module from CPAN.
>
> Could we get a little more detail in these?
That answer is a bit light, but most FAQ answers give you what you need
to know to do more research on your own. They aren't meant to be
everything you need to know on the subject.
If someone has more information on any of the entries, I can
incorporate that into the current answers.
Thanks,
--
Posted via a free Usenet account from http://www.teranews.com
| |
| xhoster@gmail.com 2007-08-22, 7:04 pm |
| Bill H <bill@ts1000.us> wrote:
> On Aug 21, 9:03 am, PerlFAQ Server <br...@stonehenge.com> wrote:
>
> I like these perl faq postings and have learned a lot from them, but
> is it possible to get more details in them? For instance this one.
> This is a very interesting subject:
>
> 8.39: How do I set CPU limits?
>
> But it only gives a one line answer:
>
> Use the BSD::Resource module from CPAN.
>
> Could we get a little more detail in these?
I agree. The docs for BSD::Resource seem to really be targeted to people
you already understand the use of these limits from C and are now just
trying to port that knowledge to Perl. It isn't very good for people
who are new to the concept in the first place. Also, many of the examples
it gives are incomplete--they depend on using variables that have never
been set, and isn't obvious what they are examples of in the first place.
> A cursory (and I do mean
> cursory) look at BSD::Resourse on CPAN gives details on how to
> implement it but really doesnt explain upfront what it will actually
> do.
Down somewhere in the guts it does say:
Processes have soft and hard resource limits. On crossing
the soft limit they receive a signal (for example the
"SIGXCPU" or "SIGXFSZ", corresponding to the "RLIMIT_CPU"
and "RLIMIT_FSIZE", respectively). The processes can trap
and handle some of these signals, please see "Signals" in
perlipc. After the hard limit the processes will be ruth-
lessly killed by the "KILL" signal which cannot be caught.
But it isn't easy to find and understand for someone who doesn't already
know the answer.
> Does it set how much CPU time a program can use, or a percentage
> of usage, or a time period before it will be stopped?
CPU time, not percentage, and not wall time.
How about something like this:
8.39: How do I set CPU limits?
Use the BSD::Resource module from CPAN.
As an example:
use BSD::Resource;
setrlimit(RLIMIT_CPU,10,20) or die $!;
This sets the soft and hard limits to 10 and 20 seconds, respectively.
After 10 seconds of time spent running on the CPU (not "wall" time),
the process will be sent a signal (XCPU on some systems) which, if not
trapped, will cause the process to terminate. If that signal is
trapped, then after 10 more seconds (20 seconds in total) the process
will be killed with a non-trappable signal.
See the BSD::Resource and your systems documentation for the gory
details.
It would also be nice if it described what other modules to use on
systems that don't support BSD::Resource, if anyone can contribute
that information.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
| |
| brian d foy 2007-08-25, 8:03 am |
| In article <20070822124353.549$V4@newsreader.com>, <xhoster@gmail.com>
wrote:
>
> 8.39: How do I set CPU limits?
>
> Use the BSD::Resource module from CPAN.
> As an example:
>
> use BSD::Resource;
> setrlimit(RLIMIT_CPU,10,20) or die $!;
>
> This sets the soft and hard limits to 10 and 20 seconds, respectively.
> After 10 seconds of time spent running on the CPU (not "wall" time),
> the process will be sent a signal (XCPU on some systems) which, if not
> trapped, will cause the process to terminate. If that signal is
> trapped, then after 10 more seconds (20 seconds in total) the process
> will be killed with a non-trappable signal.
>
> See the BSD::Resource and your systems documentation for the gory
> details.
I've updated perlfaq8 with your answer. It should appear in the next go
around.
Thanks, :)
--
Posted via a free Usenet account from http://www.teranews.com
|
|
|
|
|