The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
passing variable from bash to perl from bash script arsidh Shell Programming and Scripting 10 06-04-2008 09:25 AM
Why generate "ash and bash" different output for same bash script? s. murat Shell Programming and Scripting 0 05-26-2008 04:19 AM
Bash under AIX 5.3 taupin AIX 4 03-21-2008 03:03 AM
From bash to csh and zsh lev_lafayette Shell Programming and Scripting 10 09-10-2007 08:48 PM
Bash it! Bash it! SoulForge Shell Programming and Scripting 5 11-22-2002 10:02 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 10-31-2007
Registered User
 

Join Date: Oct 2007
Posts: 9
Bash: how to do it?

Hi

My problem is that i need to measure given command statistics (time, mem, etc) with shell script
My script must basically do two things:
1. Measure overall command statistics (it is total time, maximum memory use during runtime, etc)
2. Measure command statistics in given periods of time during it's run (once a x seconds)
Then i have few questions:
1. what is the best method for checking command statistics during runtime (for example ps returns process time in seconds, but i need better resolution (are jeffes realible))
2. How to make gathering data during run and after that possible. my idea is that i test given command overall statistics with time command, and use some other command to test statistics during its runtime, but...
how to detect that command finished?
let's say that i use time for overall statistics, i have to do something like that
[time given_command...] &
part_of_script_testing_given_command_during_runtime
how to get pid of [time given_command...] in the main script?

and if you know some examples of such script, can you give some links?

if you know please help thx
Charles
Reply With Quote
Forum Sponsor
  #2  
Old 11-01-2007
sysgate's Avatar
Unix based
 

Join Date: Nov 2006
Location: /root
Posts: 1,200
You can get the pid of "time command" by grepping for "command" name, for example : "time cat" ; "pgrep cat" - this will return the PID of cat. Disadvantage : if you have multiple cat command, "pgrep" will return all of them.
Code:
for i in `seq 1 100`; do time ps -ef >> logfile.log; sleep 2; done
this will output the return of time command on STDOUT every two seconds, while storing the output of the actuall command in logfile.
Also, if your distro has it, take a look at the options of "usr/bin/time" - this is kinda different than the "time" command.
For the other things that you're asking, can you please provide some examples ?
Reply With Quote
  #3  
Old 11-01-2007
Registered User
 

Join Date: Oct 2007
Posts: 9
hm... there is problem about /usr/bin/time. It doesn't return maximum resident set size, which i need too (it always return 0 instead). Is there a way to get maximum resident set size of a process that has finished?

also this:
Code:
for i in `seq 1 100`; do time ps -ef >> logfile.log; sleep 2; done
isn't exactly what i wast thinking about. what i aim is something like that:

Code:
time -o "logfile.txt" -f "parameters i want" my_given_command &
childpid=$!
for i in 'seq 1 100' do; gether_and_write_childpid_statistics; sleep 1; done;
write_statistics_from_time_command
But the problem with it is that:
1. i would like to know if childpid has finished and break the loop then (better if i could do it in sleep command, but i dont know if its possible). i don't want to gather data from finished process
2. i would like to have reliable command for monitoring childpid (ps only returns cpu time in seconds, i don't know if i can monitor it better)
3. and the problem with time that i write about at the beginning, how to obey it?

Thx

Last edited by sopel39; 11-01-2007 at 08:53 AM. Reason: code tags
Reply With Quote
  #4  
Old 11-02-2007
Registered User
 

Join Date: Oct 2007
Posts: 9
Also is there a command that wait's for child for specific amount of time and if child wont finish it return error after that period?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:03 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0