Memory allowance in shebang

B

Bart Van der Donck

Hello,

My perl program is running in the background and should not exceed too
much of the machine's resources.

Therefore I imagine a shebang like this:

#!perl -AllowThisProcessNoMoreThan15%OfAvailableResources
# code starts

Or

#!perl
use Run::NiceMode("max 15%");
# code starts

Where the 15% would be the CPU-column in the UNIX 'top' program.

I am aware of buffering/allowance methods on the OS-level, but I
couldn't find one that can be used for a specific Perl script. Is this
possible at all ? Maybe material for PerlFAQ 3.16, too.

Thanks,
 
B

Brian Wakem

Bart said:
Hello,

My perl program is running in the background and should not exceed too
much of the machine's resources.

Therefore I imagine a shebang like this:

#!perl -AllowThisProcessNoMoreThan15%OfAvailableResources
# code starts

Or

#!perl
use Run::NiceMode("max 15%");
# code starts

Where the 15% would be the CPU-column in the UNIX 'top' program.

I am aware of buffering/allowance methods on the OS-level, but I
couldn't find one that can be used for a specific Perl script. Is this
possible at all ? Maybe material for PerlFAQ 3.16, too.

Thanks,


$ perldoc -q limit

Found in /usr/lib/perl5/5.8.6/pod/perlfaq8.pod
How do I set CPU limits?

Use the BSD::Resource module from CPAN.
 
P

Peter J. Holzer

Bart said:
My perl program is running in the background and should not exceed too
much of the machine's resources. [...]
#!perl
use Run::NiceMode("max 15%");
# code starts

Where the 15% would be the CPU-column in the UNIX 'top' program.

What Unix variant are you using? I know of no general UNIX way to
restrict a program to a certain percentage of the CPU, but some specific
Unix variants may have one.

But is that really necessary? Why not allow the process to use the CPU
fully if no other process is using it? On Unix, there is the system call
nice(2) (available for perl in the POSIX package), which lets you tell
the OS how "nice" the process should be. A nice value of 0 is normal for
interactive processes. Some shells set background processes
automatically to a small positive niceness (e.g., 5). If you set the
value to 19 (the maximum), the process basically gets only run if no
other process wants the CPU. Use intermediate values for finetuning on
a busy system (but be aware that the CPU is often not the bottleneck).

hp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top