Results 1 to 7 of 7
Hi,
Our system at work has just moved from Tru64 -> RH Linux.
On Tru64 we used to be able to use the 'ps aux' command to see the status ...
- 03-24-2010 #1Just Joined!
- Join Date
- Mar 2010
- Posts
- 4
Process Status
Hi,
Our system at work has just moved from Tru64 -> RH Linux.
On Tru64 we used to be able to use the 'ps aux' command to see the status of a process, and figure out if that process was actually 'running'.
We could test the 'CPU%' field, and if its > 0, then it was running.
However, on Linux, this field is now the total % the process has used within its life time, so this cannot be used now.
I've tried using the process 'State', but on some processes that are running, the state can change from R, D (which is ok form me), but sometimes even through its running, for a second it goes to stat 'S'.
This means that sometimes, my script misses these processes, as I cant tell if they are running or not.
I notice that 'top' shows the CPU% that the process is currently taking up, like it did in Tru64, so there must be a way of doing it.
Thanks for any help,
Rob.
- 03-24-2010 #2Just Joined!
- Join Date
- Mar 2010
- Posts
- 4
Try using ps -ely
Does that give you what you need?
- 03-24-2010 #3Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
What data do you want to see, specifically? And actually the CPU% field is the current CPU usage, not total over time. The state of the program is also useful. For example, to get just the name, pid, parent pid, cpu%, and state you could do this:
Anyway, see the ps man page for more information.Code:ps axo comm,pid,ppid,pcpu,stat
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 03-25-2010 #4Just Joined!
- Join Date
- Mar 2010
- Posts
- 4
Hi,
Hmmm... I'm prety sure that CPU% is not just the amount its taking up at that 'time'... ie not the current CPU%.
On Tru64 it was, but its not in Linux.
From man of ps on Linux:
As I said also, the stat of the PID changes from R,D and sometimes to 'S'.CPU usage is currently expressed as the percentage of time spent running during the entire lifetime of a process. This is not ideal,
and it does not conform to the standards that ps otherwise conforms to. CPU usage is unlikely to add up to exactly 100%.
It seems to go into 'S' state then the proc is in 'posix_lock_file_wait'
Even though its a 'running' process, so any scripts looking for 'R' or 'D' state to find running procs, misses some when it going into 'S' state quickly.
Ta,
Rob.
- 03-31-2010 #5Just Joined!
- Join Date
- Mar 2010
- Posts
- 4
Hi,
Well, I really cant find a way to identify if a process is actually running, on Linux.
Bit strange that there doesn't seem to be a way
I guess there could be some way via 'C', since 'top' seems to report it correctly, but I would have liked to do it via bash/script if possible.
Anyone else have any 'bright' ideas.
Thanks,
Rob.
- 03-31-2010 #6Just Joined!
- Join Date
- Mar 2010
- Posts
- 4
That doesn't sound right. 'ps' shoud display all running processes. If you can't see it on the list perhaps it isn't running?!?
Start the program you are trying to monitor and then run the 'ps' command described above and then paste the command you ran and it's output on this thread. Maybe we can help decipher what is happening.
- 03-31-2010 #7
I would question if it was on Tru64 either because it poses a technical problem. Without a defined begin_time and end_time, calculating out a percentage of cpu is problematic and since 'ps' is a single point-in-time snapshot then a calculation is needed. Technically, at the exact snapshot timeframe only the 'ps' command and kernel should be using any cpu. The ps's cpu% on linux is defined as cputime/realtime to give an overall percentage used over that time period.
I havent dissected the code for 'top', but it has the advantage of gathering the statistics over a couple of seconds and can then use that time period to determine how much cpu was used by the processes.
I hope im explaining this well, but to rehash: in order to get a usable percentage of cpu utilization you will need samplings from a defined beginning point and defined ending point in time. This is something that a single point in time snapshot cannot provide.
--Brett


Reply With Quote
