Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^4: Equal strings don't match!

by pl (Initiate)
on Jul 30, 2008 at 19:16 UTC ( [id://701241]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Equal strings don't match!
in thread Equal strings don't match!

The programm is working now! I developed a monitoring application for linux. I have other arrays with info about each process that I get from the proc fs...This might help to understand:
sub get_data_from_proc_fs{ opendir(PROC,"/proc"); @PROC = readdir PROC; closedir(PROC); @pid = grep /[0-9]/, @PROC; for($k=0;$k<@PID;$k++){ open(STAT,"<","/proc/$PID[$k]/stat"); ($STAT) = <STAT>; push(@app,(split(" ",$STAT))[1]); push(@pgrp,(split(" ",$STAT))[4]); close(STAT); open(CMDLINE,"<","/proc/$PID[$k]/cmdline") ; ($CMDLINE) = <CMDLINE>; push(@cmd,$CMDLINE); close(CMDLINE); } $/ = "\0"; chomp(@cmd); $/ = "\n"; } #####some code here# &get_data_from_proc_fs ; &get_system_date ; $a = 0 ; $PROC_FS_NEW = 0 ; while( $a < $PS_MONITOR ){ $b = 0 ; $found = 0 ; while( $b < $PS_PROC_FS ){ if( ($cmd_monitor[$a] eq $cmd[$b]) && ($pgrp[$b] eq $pid[$b]) +){ if( $first_time == 1 ){ $status = "NORMAL" ; $process = "${app[$b]}_${pid[$b]}" ; &print_status_info($process,$cmd[$b],$pid[$b]) ; $found++ ; } &save_info_about_running_processes_to_monitor ; $PROC_FS_NEW++ ; } $b++ ; } if(( $found == 0 ) && ( $first_time == 1 )){ $status = "ERROR" ; &print_status_info($app_m[$a],$cmd_m[$a]) ; } $a++ ; #####code continues...#

Replies are listed 'Best First'.
Reinventing Proc::ProcessTable? (was Re^5: Equal strings don't match!)
by AltBlue (Chaplain) on Jul 31, 2008 at 02:13 UTC

    Looks like you're trying to reinvent Proc::ProcessTable. I'd recommend you to use that, at least this way you'll avoid most of the pitfalls your code presents (it may crash in a million ways as you don't handle the *many* errors that may occur when processing files from such a volatile file-system as /proc).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://701241]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2025-06-19 03:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.