How to find inactive time of a process?


 
Thread Tools Search this Thread
Top Forums Programming How to find inactive time of a process?
# 1  
Old 01-03-2011
How to find inactive time of a process?

Hi,

I'm trying to write a C program that finds idle login sessions on RHEL6 and kill the sessions which are idle(inactive) for, say, more than 15 minutes. I tried to use procfs.h is my code. But it doesn't seem to support enough API's as OS Solaris does.(Solaris supports API's that can populate structures for process status).
Now I am thinking of using /proc myself to do this. Can someone help me with the following?
I need to get the pid from the process name(eg. bash/ssh or some other login sessions) - this can be done using popen.
Then,
1) Find the inactive time for that pid using /proc file system
2) In case of bash, make sure it's not from a console session

Then if both the above conditions are satisfied kill the process and hence kill the session.

Could someone please help with point 1 and 2?

Last edited by shreeda; 01-03-2011 at 02:21 AM..
# 2  
Old 01-03-2011
why not just use the TMOUT variable inside the shell instead of shoehorning a solution from the outside?
# 3  
Old 01-03-2011
Quote:
Originally Posted by Corona688
why not just use the TMOUT variable inside the shell instead of shoehorning a solution from the outside?
Afaik, TMOUT is possible for shell logins. But I need to consider the sessions like some Command Line Interface applications also. For those cases I think we need the C approach itself. What do you think?
# 4  
Old 01-03-2011
Quote:
Originally Posted by shreeda
Afaik, TMOUT is possible for shell logins. But I need to consider the sessions like some Command Line Interface applications also
What is that?
# 5  
Old 01-03-2011
Quote:
Originally Posted by Corona688
What is that?
There are some provisioning applications running on the server which also use login mechanisms. The users which are using such applications may not use any shell login (Instead they can login through a GUI from outside).
And a doubt here, even if they login to a shell and launch such an application and become idle, will the shell be considered idle? I think the shell will remain active! In such a case TMOUT may not help me.

So I need to consider those sessions for inactivity time too. I mean, if such a login session is in progress, I need to kill that session first. Am I right?
# 6  
Old 01-03-2011
Quote:
Originally Posted by shreeda
And a doubt here, even if they login to a shell and launch such an application and become idle, will the shell be considered idle? I think the shell will remain active! In such a case TMOUT may not help me.
You are correct. When a command is being run, the shell won't consider itself to be idle.

It would still be better to work with the applications and window environments than to try and extract idle information from outside. Process statistics are likely completely useless with respect to how long the user has been idle.
# 7  
Old 01-03-2011
Quote:
Originally Posted by Corona688
You are correct. When a command is being run, the shell won't consider itself to be idle.

It would still be better to work with the applications and window environments than to try and extract idle information from outside. Process statistics are likely completely useless with respect to how long the user has been idle.
I didn't quite get itSmilie. Could you please explain? An example will be useful I think. Sorry for troubling, I'm new to these kinds of problems Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Assistance with my one line command to find all inactive kernels

Hello Forum, I'm using the following command to find all inactive kernels installed on my RHEL server: $ rpm -qa | grep '^kernel-' |grep -vE `uname -r` but the result is in two lines: kernel-3.10.0-1062.1.1.el7.x86_64 kernel-3.10.0-1062.el7.x86_64 Is there a one line command I can... (3 Replies)
Discussion started by: greavette
3 Replies

2. Programming

Find gaps in time data and replace missing time value and column 2 value by interpolation in awk

Dear all, I am kindly seeking assistance on the following issue. I am working with data that is sampled every 0.05 hours (that is 3 minutes intervals) here is a sample data from the file 5.00000 15.5030 5.05000 15.6680 5.10000 16.0100 5.15000 16.3450 5.20000 16.7120 5.25000... (4 Replies)
Discussion started by: malandisa
4 Replies

3. UNIX for Advanced & Expert Users

Find Inactive VG

lsvg -o shows active VGs. Is there a way to find inactive VGs with a command? Please advise. (2 Replies)
Discussion started by: Daniel Gate
2 Replies

4. Shell Programming and Scripting

How to calculate time difference between start and end time of a process!

Hello All, I have a problem calculating the time difference between start and end timings...! the timings are given by 24hr format.. Start Date : 08/05/10 12:55 End Date : 08/09/10 06:50 above values are in mm/dd/yy hh:mm format. Now the thing is, 7th(08/07/10) and... (16 Replies)
Discussion started by: smarty86
16 Replies

5. Shell Programming and Scripting

Find and Convert UTC Time to PST Time

Hello All - I have a script that grabs data from the net and outputs the following data 46029 46.144 -124.510 2010 07 26 22 50 320 4.0 6.0 2.2 9 6.8 311 1012.1 -0.9 13.3 13.5 13.3 - - 46041 47.353 -124.731 2010 07 26 22 50 250 2.0 3.0 1.6 8 6.4 - 1011.6 - ... (0 Replies)
Discussion started by: drexnefex
0 Replies

6. Linux

Process start time not showing correct time

Process start time is not showing the correct time: I had started a process on Jun 17th at 23:30:00. Next day morning when I run the command "ps -ef | grep mq", the process is showing the start date of Jun 17th but the start time is 00:16:41 Day/Date is setup correctly on the server. It... (2 Replies)
Discussion started by: hemangjani
2 Replies

7. UNIX for Advanced & Expert Users

Process accounting and Shell process time

Hi All, I am running the following accounting on one of my executable, $ accton /home/myexe-acct $ ./myexe $ accton When I check the process timings I get the below result, Shell process time: 300ms myexe time: 100ms I want to know on why the shell(sh) process is taking so much time... (1 Reply)
Discussion started by: santoshbr4
1 Replies

8. UNIX for Dummies Questions & Answers

how to Decrease priority of a particular process in time of process creation

how to decrease priority of a particular process in time of process creation... and also how to decrease priority of a particular process after process creation.. can any one please help me out... (2 Replies)
Discussion started by: Ramkum
2 Replies

9. Shell Programming and Scripting

how to find the chid process id from given parent process id

how to find the chid process id from given parent process id.... (the chid process doesnot have sub processes inturn) (3 Replies)
Discussion started by: guhas
3 Replies
Login or Register to Ask a Question