LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 01-18-2007, 02:21 AM   #1
musthafa
LQ Newbie
 
Registered: Jan 2007
Posts: 6

Rep: Reputation: 0
Track idle processes


Ho Folks,

I would like to figure out the processes that are idle for more than 5 hours. What is the command to use? TIA.

Regards,
Ahamed
 
Old 01-18-2007, 07:20 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Hello and welcome to LQ, hope you like it here.

I would like to figure out the processes that are idle for more than 5 hours.
I rephrase that as "processes that are and older than 5 hours and have idle state right now" since I don't know how to track idle vs running state w/o keeping per-process, per-timeslice statistics. Only requirement of Bash kludge below is 'procstat' which you can get at Senko.net because else I'll have to look at the kernel source for /proc/PID/stat fields. Hopefully I overlooked something essential and somebody will present a qualitatively better way. YMMV(VM):

Code:
#!/bin/sh --
AGE=$[60*60*5]; echo -en "Aged ${AGE}: "; /bin/ps ax -eostate,pid --sort=state 2>/dev/null|\
while read STATE PID; do case "${STATE}" in S*) STARTTIME=(`procstat -t "${PID}" 2>/dev/null|\
while read LINE; do case "${LINE}" in Started*) echo "${LINE}";; esac; done`); if [ -n \
"${STARTTIME[2]}" ]; then STARTTIME=${STARTTIME[2]//.*/}; STARTTIME=`date +%s --date=\
"${STARTTIME}"`; [ $[`date +%s`-${STARTTIME}] -gt ${AGE} ] && echo "${PID}"; fi;; esac; done|\
xargs; exit 0
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
One track mind Titan2k SUSE / openSUSE 1 07-24-2005 02:49 PM
programming ideas: track and terminate child processes feetyouwell Programming 2 09-23-2004 10:27 AM
monitoring active processes and identifying the required processes. gajaykrishnan Programming 2 08-13-2004 01:58 AM
Track a thread ithawtewrong LQ Suggestions & Feedback 1 07-19-2004 04:28 PM
5 httpd processes running on an idle box? J_Szucs Linux - Networking 2 04-07-2003 08:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 04:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration