Sekhar Reddy has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I need to find the CPU and Memory Utilization of a perl script.

Can you help me is there any readily available script to monitor this?

I have seen one in this link "Determining memory usage of a process...", but i don't have access(privileges) to install the perl modules(Proc::ProcessTable).

Thank you for your help,

Reddy.

2018-08-25 Athanasius Linkified the link

  • Comment on Memory and CPU utilization scripts without any installations of modules

Replies are listed 'Best First'.
Re: Memory and CPU utilization scripts without any installations of modules
by soonix (Chancellor) on Aug 22, 2018 at 15:21 UTC
Re: Memory and CPU utilization scripts without any installations of modules
by zentara (Cardinal) on Aug 22, 2018 at 16:00 UTC
    Here is another example, all modules are standard. Also see Obtaining data from the top command via a pipe
    #!/usr/bin/perl use warnings; use strict; use IPC::Open3; my $pid = shift || $$; my $pid1 = open3(\*WRITE,\*READ,0,"/bin/sh"); #if \*ERROR is false, STDERR is sent to STDOUT while(1){ print WRITE "ps -o rss= -p $pid\n"; select(undef,undef,undef,.1); # a small delay my $size = <READ>; print "$size"; }

    I'm not really a human, but I play one on earth. ..... an animated JAPH
Re: Memory and CPU utilization scripts without any installations of modules
by davido (Cardinal) on Aug 22, 2018 at 19:19 UTC

    Reading from /proc/$pid/stat is also pretty easy, and while there are probably some portability concerns, it is at least the same across centos and ubuntu, which are where I spend most of my time.

    vsize is part of the contents of the file.


    Dave