ps -elf AND grep for changes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ps -elf AND grep for changes
# 1  
Old 04-16-2012
ps -elf AND grep for changes

Hoping theres something already out there like this.

I have a list of proccesses who's "ps -elf" (field 10) values I need to continuously monitor and if the values of field 10 start to signiciantly increase (double, triple) then do something. The field 10 is the "memory size" field.

(these are constant process names)
Code:
process1
process2
process3

Code:
foreach proccx ( process1 process2 process3 )
  initvar1,2,3 = ps -elf |grep $proccx |awk '{print $10}'
end

So now I would have 3 initial vars, (initvar1, initvar2, and initvar3)

Now enter some kind of a monitoring loop "for each" of the processes.
Code:
foreach proccx ( process1 process2 process3 )
  set curvar1,2,3 = ps -elf |grep process1 |awk {print $10}'
  if $curvar1 > $initvar1 * 2 , do something.
end

sleep 5
end


cshell or bash on solaris v10. The real problem I have found is variable "passing"

Last edited by Franklin52; 04-17-2012 at 03:28 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 04-16-2012
You could try this in bash:

Code:
#!/bin/bash
while true
do 
    while read pid mem
    do
       [ -z "${orig[pid]}" ] && orig[pid]=$mem
       if [ $((orig[pid]*2)) -lt $mem ]
       then
           echo "$pid has grown from ${orig[pid]} to $mem"
       fi
    done  < <(ps -elf | awk '/[p]rocess1|[p]rocess2|[p]rocess3/{print $4 " " $10}')
    sleep 5
done

Things to think about:
process ends - should really be removed from orig array, this one isn't a big deal.

Last edited by Chubler_XL; 04-16-2012 at 11:11 PM..
This User Gave Thanks to Chubler_XL For This Post:
# 3  
Old 04-17-2012
thank you

now wheres that thank-you button?
# 4  
Old 04-17-2012
What operating system are you on? Most have built in monitoring alerts for such things.
# 5  
Old 04-17-2012
SOLARIS 10

the above script by Chubler_XL works great. The only issue is that the process names (process1, process2, process3) are not always very unique, and often just using the unique part of the name will reference multiple processes. I'd rather generate up a list of PIDs and then use this list for monitoring. I'm trying to figure out a way to do this based on just the PID

Also,
If there is an Solaris OS utility for this type of monitoring please let me know.
Thank you all so much!
Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Solaris

Wrong ELF class

guys anyone knows a solution for this? wrong ELF class: ELFCLASS64 pwrcard:cms-dev:/pcard16/pwrcard/src/interfaces/interface_host>isainfo -v 64-bit sparcv9 applications vis2 vis 32-bit sparc applications vis2 vis v8plus div32 mul32... (1 Reply)
Discussion started by: q8devilish
1 Replies

2. Programming

A help to create an ELF file

Hi!!! How do I create a file .ELF? What code should I use, could help me with a simple code or example? I know programming to Windows by important languages but this seems to be more sistematical, and I really don't know how to. (2 Replies)
Discussion started by: linecoder
2 Replies

3. BSD

DG/UX ELF binary support

Anyone, perhaps got DG/UX ELF binaries running on an old *BSD system? I've tried a lot of different kinds, with COMPAT_SVR4 compiled in and ibcs support, all ended up with Segement Fault or Bus Error errors. (2 Replies)
Discussion started by: dgux
2 Replies

4. Solaris

Not a Vaild ELF File

Hi Anyone, I have two disks , one is primary and anothe is mirror. I checked my mirror disk , It was fine. After that i booted from my primary disk, did some installations regarding kernel patches. It did not get booted properly. It says ==================== Not a valid... (2 Replies)
Discussion started by: jegaraman
2 Replies

5. Programming

ELF-string table

hello everybody! I want to read the string table of an object file(which is in ELF format). I get the sh_name value but i cant find a way to read the value in the string table that this index represent. I program in C. thanx a lot folks! (3 Replies)
Discussion started by: nicos
3 Replies

6. UNIX for Dummies Questions & Answers

Running elf files

I have a few questions about elf files and how they are executed. When gcc compiles a elf file it creates an executable. Is this executable then run directly by the hardware or does the kernel get involved, interpret the elf file and place the asm code directly in memory. Cheers (0 Replies)
Discussion started by: mshindo
0 Replies

7. Linux

editing ELF file

Hello, This is not exactly relevant to Linux kernel but I'm gonna ask any way. Is there any way I can modify a 64-bit ELF object file to make it look like 32-bit ELF object file and link it (using `ld`) with 32-bit ELF file? I tried libelf but was unsuccessful. I had this pretty link... (1 Reply)
Discussion started by: tejuwala
1 Replies

8. UNIX for Advanced & Expert Users

What does bad elf flags mean?

Hi all! Could anybody tell me what this means? # /usr/local/sbin/sshd ld.so.1: /usr/local/sbin/sshd: fatal: /usr/local/lib/libcrypto.so.0.9.6: bad ELF flags value: 256 Killed Thanx (1 Reply)
Discussion started by: penguin-friend
1 Replies
Login or Register to Ask a Question