Visit Our UNIX and Linux User Community


Inactive Session


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Inactive Session
# 8  
Old 06-11-2006
If ksh is the login shell, try to set TMOUT variable in user's .profile and see if it helps you.
# 9  
Old 06-11-2006
I think this is either going the wrong way, or maybe I'm not understanding what's being said.

The "idle process" you are talking about is not telnet or the shell, but rather an instance of the application that's being run through said telnet session, right?

In other words:
User telnets to box, starts application.
User closes terminal without properly exiting application.
User's session terminates, but application process keeps on running.

And what you want to find out is how to differenciate those application processes that are still running that where not properly shut down when the user terminated his telnet session, so you can safely kill them. Right?

If that's the case, i.e., the application process doesn't die when the telnet session is killed, then loking at user idleness is not going to help, since there actually won't be a user session associated with said application process.

I'd say first that I agree with what grial said - the app should catch ithe session being terminated -, anyway, without knowing specifics - and you know the devil is in the details -, I'd think that a simple parse of ps -ef would do the trick. Rather than looking for idle sessions, you can match PID's with a simple script. Quick example:

user1 logs in, so it creates some processes. One of the is the user's shell. When that user starts some application, that application process should show the user's shell as the application process' parent ID. I would think a simple match of said IDs in a cron job would do the trick; something like:

Code:
process=$(ps -ef | grep <my_application_process> | awk '{print $2}') 
parent=$(ps -ef | grep <my_application_process> | awk '{print $3}') 
count=$(ps -ef | grep ${parent} | wc -l)  ## this should catch at least 2 processes: 
                                          ## the PPID of application and the PID of
                                          ## user's shell
if (( ${count} < 2 )); then  ## if it only catches one, it'd mean user is no longer logged in
kill -9 ${process}
fi

Now, the above example is very simplified. You'd probably need to play around with arrays and other stuff, but hopefully it gives you the idea.

And, like I said before, if I misunderstood what's being asked, then, nevermind Smilie
# 10  
Old 06-12-2006
Quote:
Originally Posted by System Shock
In other words:
User telnets to box, starts application.
User closes terminal without properly exiting application.
User's session terminates, but application process keeps on running.
That's what I think It is.

Quote:
Originally Posted by System Shock
I'd say first that I agree with what grial said - the app should catch ithe session being terminated -, anyway, without knowing specifics - and you know the devil is in the details -, I'd think that a simple parse of ps -ef would do the trick. Rather than looking for idle sessions, you can match PID's with a simple script. Quick example:
Thanks. Of course, I would prefer the "programming solution" but, this would be a possible one. The easy one for me.

Quote:
Originally Posted by System Shock
Code:
process=$(ps -ef | grep <my_application_process> | awk '{print $2}') 
parent=$(ps -ef | grep <my_application_process> | awk '{print $3}') 
count=$(ps -ef | grep ${parent} | wc -l)  ## this should catch at least 2 processes: 
                                          ## the PPID of application and the PID of
                                          ## user's shell
if (( ${count} < 2 )); then  ## if it only catches one, it'd mean user is no longer logged in
kill -9 ${process}
fi

Now, the above example is very simplified. You'd probably need to play around with arrays and other stuff, but hopefully it gives you the idea.

And, like I said before, if I misunderstood what's being asked, then, nevermind Smilie
But you forgot "grep -v grep" Smilie

Anyway. Doing a little search on google (I'm not a C programmer), I came across with this:

http://www.metalshell.com/view/source/92/

It's a peace of code in which signals are catched and treated. Basicaly, it uses the "signal" system call to catch a (HUP) signal. Perhaps it helps you...
# 11  
Old 06-12-2006
Quote:
Originally Posted by grial

But you forgot "grep -v grep" Smilie
Like I said, the devil is in the details Smilie
# 12  
Old 06-12-2006
yeah! That's right! heheheheh Smilie
# 13  
Old 06-22-2006
Hi all,

Sorry for late reply and thanks for your advise.

This is exactly the problem I am facing now. But it is not necessary user logout abnormally, sometime could be due to network connection failure and caused the application ended. I noticed that the shell and the application PID are both still active. Below are some typical example that extract from server.

root# who |grep 10.1.1.144
jbmkt1 pts/82 Jun 22 11:11 (10.1.1.144)
jbmkt1 pts/83 Jun 22 09:50 (10.1.1.144)
jbmkt1 pts/226 Jun 22 10:34 (10.1.1.144)
jbmkt1 pts/249 Jun 22 10:53 (10.1.1.144)

root@ # ps -ef |grep db |grep jbmkt1
jbmkt1 20432 20331 2 10:53:34 pts/249 0:52 /u/recital/db.exe -x menu
jbmkt1 22156 22089 0 11:11:46 pts/82 0:00 /u/recital/db.exe -x menu
jbmkt1 17993 17948 2 10:34:44 pts/226 0:54 /u/recital/db.exe -x menu
jbmkt1 10055 9955 2 09:50:55 pts/83 2:27 /u/recital/db.exe -x menu

root # ps -u jbmkt1
9955 pts/83 0:00 sh
20432 pts/249 1:00 db.exe
22156 pts/82 0:00 db.exe
20331 pts/249 0:00 sh
22089 pts/82 0:00 sh
17948 pts/226 0:00 sh
17993 pts/226 1:03 db.exe
10055 pts/83 2:37 db.exe


from the above you can see those logins earlier have ended abnormally due to network problem, but the session seems still active for both shell and application, I will have to manually verify and kill those inactive session, if not the load will getting higher and slower.

This is what I meant, but if you based on the count, it is also appropriate, right ?

Please advise further.

Have a nice day.

Thanks & Rgds
T.W.Low
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #993
Difficulty: Medium
Illumination is a free and open-source Unix operating system based on OpenSolaris.
True or False?

7 More Discussions You Might Find Interesting

1. Solaris

Difference between the desktop session and console session

what is the difference between desktop session and console session in solaris as i am wondering we use option -text for the former and -nowin for the later (1 Reply)
Discussion started by: kishanreddy
1 Replies

2. Shell Programming and Scripting

Determining if session is a login session

Besides 'who am i' and 'tty' what commands could be used to determine if a session is interactive as compared to a web process or cron process. Any command should work with the common unix variants. (3 Replies)
Discussion started by: jgt
3 Replies

3. HP-UX

ssh session getting hung (smilar to hpux telnet session is getting hung after about 15 minutes)

Our network administrators implemented some sort of check to kill idle sessions and now burden is on us to run some sort of keep alive. Client based keep alive doesn't do a very good job. I have same issue with ssh. Does solution 2 provided above apply for ssh sessions also? (1 Reply)
Discussion started by: yoda9691
1 Replies

4. Solaris

I am not able to login in gnome session and java session in Sun solaris 9& 10

I am not able to login in gnome session and java session in Sun solaris 9& 10 respectively through xmanager as a nis user, I am able to login in common desktop , but gnome session its not allowing , when I have given login credentials, its coming back to login screen, what shoul I do to allow nis... (0 Replies)
Discussion started by: durgaprasadr13
0 Replies

5. Shell Programming and Scripting

Hiding Directories on a Session by Session basis

Hi, Apologies if anyone has read my recent post on the same subject in the Linux forum, just thought actually the solution might more likely come from scripting. Essentially, I am trying to restrict access to directories based on the user's name AND their location on a session-by-session... (3 Replies)
Discussion started by: en7smb
3 Replies

6. Shell Programming and Scripting

sqlplus session being able to see unix variables session within a script

Hi there. How do I make the DB connection see the parameter variables passed to the unix script ? The code snippet below isn't working properly. sqlplus << EOF user1@db1/pass1 BEGIN PACKAGE1.perform_updates($1,$2,$3); END; EOF Thanks in advance, Abrahao. (2 Replies)
Discussion started by: 435 Gavea
2 Replies

7. UNIX for Advanced & Expert Users

inactive pages

hi, plz tell me, how can get the inactive pages in HP UX. bye.... (1 Reply)
Discussion started by: venkat_t
1 Replies

Featured Tech Videos