Find the answer to your Linux question:
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 ...
  1. #1
    Just 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.

  2. #2
    Just Joined!
    Join Date
    Mar 2010
    Posts
    4
    Try using ps -ely

    Does that give you what you need?

  3. #3
    Linux Guru Rubberman's Avatar
    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:
    Code:
    ps axo comm,pid,ppid,pcpu,stat
    Anyway, see the ps man page for more information.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  4. #4
    Just Joined!
    Join Date
    Mar 2010
    Posts
    4
    Quote Originally Posted by Rubberman View Post
    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:
    Code:
    ps axo comm,pid,ppid,pcpu,stat
    Anyway, see the ps man page for more information.
    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:

    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%.
    As I said also, the stat of the PID changes from R,D and sometimes to 'S'.

    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.

  5. #5
    Just 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.

  6. #6
    Just 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.

  7. #7
    Just Joined! bclark4444's Avatar
    Join Date
    Dec 2003
    Posts
    55
    Quote Originally Posted by robdon View Post
    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.
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...