Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8261249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:20:30+00:00 2026-06-08T03:20:30+00:00

Is it possible to control cpu usage using Perl script in an idle machine?

  • 0

Is it possible to control cpu usage using Perl script in an idle machine?

like some.pl 50 will consume 50% cpu, some.pl 100 will consume 100% cpu usage.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T03:20:32+00:00Added an answer on June 8, 2026 at 3:20 am

    Yes, certainly it is possible. The following snippet calculates the percentage of processor load for a certain process in an instant of time. You probably first want to collect a certain number of values and average them for a smooth result.

    Then simply, if the load is not high enough, tell the process to do work, if the load is too high, tell the process to pause work.

    use constant UTIME => 13;
    use constant STIME => 14;
    use List::Util qw(sum);
    use Time::HiRes qw(sleep);
    use autodie qw(:all);
    
    sub pidload {
        my ($pid) = @_;
        open my $pstat, '<', "/proc/$pid/stat";
        my @pstat = split ' ', <$pstat>;
        close $pstat;
        return $pstat[UTIME] + $pstat[STIME];
    }
    
    sub cpuload {
        open my $stat, '<', '/proc/stat';
        my @total = split ' ', <$stat>;
        close $stat;
        shift @total;
        return sum @total;
    }
    
    my ($pid) = @ARGV;
    my $prev_cpu = cpuload;
    my $prev_pid = pidload $pid;
    while (1) {
        sleep 0.1;
        my $now_pid = pidload $pid;
        my $now_cpu = cpuload;
        printf "%.0f\n", 100*(($now_pid - $prev_pid) / ($now_cpu - $prev_cpu));
        $prev_cpu = $now_cpu;
        $prev_pid = $now_pid;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to control autofocus feature of Android camera, using OpenCV's libnative_camera*.so ?
Possible Duplicate: Create event handler for OnScroll for web browser control I would like
Possible Duplicate: Using SendMessage to enter text into an edit control belonging to another
Is is somehow possible to control letter spacing when using Graphics.DrawString? I cannot find
Is it possible to control the scene in the Unity3D Plugin by using JavaScript?
Consider using the Default.png as the app splash image, it is possible to control
Some SONY Cameras have a FireWire interface. Is it possible to control any camera
I would like to know more about the extent it is possible to control
Is it possible to control the Tools->Options->View->View Whitespace between pages through VBA/Macros? Thanks.
is it possible to control the iAd in my application after it's launched ?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.