Sponsored Content
Full Discussion: CPU Usage of a process
Top Forums Shell Programming and Scripting CPU Usage of a process Post 302539074 by matt9949 on Friday 15th of July 2011 05:58:22 AM
Old 07-15-2011
CPU Usage of a process

Hi guys,

I am currently writing a JAVA script to monitor certain unix processes through JConsole.

Upon having lots of trouble with runtime.exec, i decided to bypass the top/ps command call and just get the information straight from /proc/*pid*/whatever.

Now i can pull back any information from any of the files I want, and the current way i determine the CPU usage of a process is as follows:

Add the UTime and STime of that process from /proc/pid/stat then divide my pidCpu by UTime + STime + NTime from /proc/stat, then multiply that by 100, should give me the % cpu usage a process is using, right?

Theory being if I get the jiffies assigned to my process, I can divide that by the total jiffies the cpu assigns.

However, my results seem to vary from the ones gathered from top and ps. What am I doing wrong?

Any input is appreciated.
 

10 More Discussions You Might Find Interesting

1. Solaris

Process CPU usage in Solaris 10

Hi All, Please let me know the command (expect top) to view the cpu usage of every process in Solaris 10. Thanks in Advance, Arun (1 Reply)
Discussion started by: arun.viswanath
1 Replies

2. AIX

CPU usage of a process

I'm trying to monitor the CPU usage of a process and output that value to a file or variable. I know topas or nmon can tell me this in interactive mode but what I need is topas-looking output that allows me to write to a file after a discrete interval. Unlike nmon data collection to a file on top... (5 Replies)
Discussion started by: robot23
5 Replies

3. UNIX for Advanced & Expert Users

Finding CPU usage by a Unix Process

Hi, I am designing a load balancer for an application. I am trying to find out the CPU usage by a specifc Unix process (PID is known). I guess I can use ps command to find that. can somebody help me in finding what exact command I should use to find? It is on AIX 5.3. Regards Asutosh (2 Replies)
Discussion started by: asutoshch
2 Replies

4. UNIX for Dummies Questions & Answers

process cpu usage

Trying to come up with a command that will show all processes sorted from highest cpu usage to lowest. Any ideas? (9 Replies)
Discussion started by: cwsmichigan
9 Replies

5. Shell Programming and Scripting

CPU Usage for a particular process

Hi, I have a shell script. But, upon execution of the same, the cpu usage is sometimes getting 100 % (checked executing top command). At that point of time, my process hangs, doesn't run anymore. I need to kill it manually. My concern is, is there any default method, by which I can check... (1 Reply)
Discussion started by: jitendriya.dash
1 Replies

6. UNIX for Advanced & Expert Users

How to find out memory & cpu usage of a process

Hi, By using time command we can determine the execution time of a process or command. bash-2.04$ time ls -l total 0 -rw-r--r-- 1 admin tac 0 Oct 6 04:46 file1 -rw-r--r-- 1 admin tac 0 Oct 6 04:46 file2 real 0m0.002s user 0m0.000s sys 0m0.001s... (5 Replies)
Discussion started by: learn more
5 Replies

7. AIX

How to trace cpu/memory usage for a process

I don't know when the process will start and end, I need write a script to trace it's cpu/memory usage when it is runing. How to write this script? (2 Replies)
Discussion started by: rainbow_bean
2 Replies

8. AIX

Problem with nmon, actual CPU usage per process

Hi all, I am currently having trouble to get nmon to print me the actual CPU usage for an interval for a process. According to the manual, something like # time nmon -t -C cron -s 5 -c 2 -F outfile real 0m0.98s user 0m0.03s sys 0m0.04s should print out at least the process... (15 Replies)
Discussion started by: zaxxon
15 Replies

9. UNIX for Dummies Questions & Answers

Average CPU and RAM usage for a process

Hi, I will be creating a process myself and I want to know the average CPU and RAM used by the process over the lifetime of the process. I see that there are various tools available(pidstat) for doing , I was wondering if it possible to do it in a single command while creation. Thanks in... (3 Replies)
Discussion started by: koustubh
3 Replies

10. Shell Programming and Scripting

Tricky situation with process cpu usage - AIX

OS: AIX so we frequently receive a lot of cpu related alerts. all types of checks have been created to keep an eye on the cpu but a lot of these checks make too much noise as the CPU is always being seen as high. the system and application owners say there's no issue with the cpu. so now,... (6 Replies)
Discussion started by: SkySmart
6 Replies
CHECKPROC(8)						       The SuSE boot concept						      CHECKPROC(8)

NAME
Checkproc - Checks for a process by full path name Pidofproc - Checks for a process by exec base name SYNOPSIS
checkproc [-vLkNz] [-p pid_file] [-i ingnore_file] [-c root] /full/path/to/executable checkproc -n [-vk] name_of_kernel_thread checkproc [-vk] basename_of_executable pidofproc [-LkNz] [-p pid_file] [-i ingnore_file] [-c root] /full/path/to/executable pidofproc -n [-k] name_of_kernel_thread pidofproc [-k] basename_of_executable SYNOPSIS LSB 3.1 pidofproc [-p pid_file] /full/path/to/executable DESCRIPTION
checkproc checks for running processes that use the specified executable. checkproc does not use the pid to verify a process but the full path of the corresponding program which is used to identify the executable (see proc(5)). Only if the inode number (/proc/<pid>/exe) and the full name are unavailable (/proc/<pid>/cmdline) or if the executable changes its zeroth argument, checkproc uses the base name (/proc/<pid>/stat) to identify the running program. Note that if the option -n for kernel thread is given only (/proc/<pid>/stat) is used. For this case a existing symbolic link (/proc/<pid>/exe) indicates that the <pid> is not a kernel thread. Extended functionality is provided by the -p pid_file option (former option -f changed due to the LSB specification). If this option is specified, checkproc tries to check the pid read from this file instead of the default (/var/run/<basename>.pid). The pid read from this file is compared against the pids of the processes that uses the specified binary. If the option -k is specified, checkproc works like killproc that is that if the if the pid_file does not exist, checkproc assumes that the daemon is not running. It is possible to use a process identity number instead of a pid file. For the possibility of having two different sessions of one binary program, the option -i ignore_file allows to specify a pid file which pid number is used to ignore all processes of corresponding process session. Note that the behaviour above is changed by the option -k. With this option, the pid read from the pid file is the only used pid (see killproc(8)) and with this option also exit codes like startproc(8) or killproc(8) are used. Without this option, the pid read from the pid file is used to search the process table for a process with an executable that matches the specified pathname. In order to avoid confu- sion with stale pid files, a not up-to-date pid will be ignored (see startproc(8)). The option -v makes checkproc print out verbose messages. The same happens if pidofproc LSB variant is used. This version also accepts also the base name only of a executable. Note that this disables the comparision of the inodes of the executable and the information found within the proc table (see proc(5)). REQUIRED
/full/path/to/executable or name_of_kernel_thread Specifies the executable which processes should be found, or alternatively, if the option Or alternated, if option -n is used, the name of the kernel thread. This argument is always required. OPTIONS
-k This option makes checkproc work like killproc(8) which changes the operation mode, e.g. the exit status of the program will be that of killproc(8). Without this option, checkproc works like startproc (8) and finds all processes with an executable that matches the specified pathname, even if a given pid file (see option -p) isn't up-to-date. Nevertheless it uses its own exit status (see section EXIT CODES). -L This option causes symlinks to be followed, as the like-named option in ls(1). Note: for the file name the original name of the program is used instead of the name of the symbolic link. -p pid_file Former option -f changed due to the LSB specification.) Use an alternate pid file instead of the default /var/run/<basename>.pid. If the option is specified and the pid_file does not exist, checkproc assumes that the daemon is not running. It is possible to use a process identity number instead of a pid file. -i ignore_file The pid found in this file is used as session id of the same binary program which should be ignored by checkproc. -c root Change root directory to root for services which have been started with this option by startproc(8). -n This option indicates that a kernel thread should be checked. In this case not the executable with its full path name is required but the name of the kernel thread. -N With this option the location of the executable is checked about NFS file system and if true the stat(2) system call is not applied on the exe symbolic link under /proc(5). Otherwise checkproc or pidofproc could be locked if the corresponding NFS server is cur- rently not online or available. This implies that the inode number check between the exectuable on the command line and the exectu- able of the exec symbolic link will be skipped. -q This option is ignored. -v Verbose output. -z This option causes checkproc to see processes even if they are in the zombie state. Without this option zombies are handled as not existent because such a process isn't alive but listed in the process table and waits on its parent process. EXAMPLE
checkproc /usr/sbin/sendmail returns all pids of running sendmail processes. checkproc -p /var/myrun/lpd.pid /usr/sbin/lpd returns the command line or the basename of the process pid found in /var/run/lpd.pid. EXIT CODES
The exit codes without the option -k have the following LSB conform conditions: 0 Program is running 1 No process but pid file found 3 No process and no pid file found 101 Wrong syntax on command line 102 Other errors If the option -k is used checkproc uses exit codes like startproc(8) or killproc(8) do: 0 Program is running 1 Generic or unspecified error 2 Invalid or excess argument(s) 4 Insufficient privilege(s) 5 Program is not installed 7 Program is not running in some cases a message is send to standard error or, if no standard error available, syslogd(8) is used. NOTE
checkproc together with the option -v just like pidof(8). The only difference is the usage of an available pid file. Only if no usable pid is given with a pid file the process table will be scanned. BUGS
Identifying a process based on the executable file and the corresponding inode number only works if the process stays alive during start- proc's execution. Processes rewriting their zeroth argument or shell scripts (the inode number of the shell executable file is not identi- cal to that of the script file) may not be identified by a filename path. FILES
/proc/ path to the proc file system (see proc(5)). /etc/init.d/ path to the SuSE boot concept script base directory as required by the Linux Standard Base Specification (LSB) (see init.d(7)). SEE ALSO
startproc(8), killproc(8), insserv(8), init.d(7), kill(1), skill(1), killall(8), killall5(8), signal(7), proc(5). COPYRIGHT
1994-2005 Werner Fink, 1996-2005 SuSE GmbH Nuernberg, Germany. AUTHOR
Werner Fink <werner@suse.de> 3rd Berkeley Distribution Nov 10, 2000 CHECKPROC(8)
All times are GMT -4. The time now is 02:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy