LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-26-2005, 06:58 AM   #1
thinkgeek
LQ Newbie
 
Registered: Jun 2005
Posts: 15

Rep: Reputation: 0
Question How to capture logout signal


Hello!

I am writing a daemon in python. In my program, I want to capture a signal for a particular event and perform some specified action. Below are more details.

1. The action to capture, is to know when the user who is currently logged in, logs out.
2. On his logout I want to update some entries into the Postgres database which will already be in connection with my program.

Bye!

thinkgeek
 
Old 06-26-2005, 09:32 AM   #2
microsoft/linux
Senior Member
 
Registered: May 2004
Location: Sebec, ME, USA
Distribution: Debian Etch, Windows XP Home, FreeBSD
Posts: 1,445
Blog Entries: 9

Rep: Reputation: 48
I'm sure this not the type of solution your looking for, but why not have your program run 'finger' every so often, then once there is nothing returned, put the data in your database. Just a thought
 
Old 06-26-2005, 11:16 PM   #3
shakezilla
Member
 
Registered: Jun 2005
Location: U.S.
Distribution: xubuntu 8.10, linux 2.6.27-11-generic
Posts: 78

Rep: Reputation: 16
Don't know about having the python daemon listening for logout.
Don't know if you can even listen for that.

What you can do is use the file "~/.bash_logout". If you look at
the bash man page, you should find it. This is from my man page:

Code:
When a login shell exits, bash reads and executes commands from the file ~/.bash_logout, if it exists.
Maybe that messes up your idea with the python daemon, but you
could still use IPC from python to fix the problem. Or if you can, just
take the pgsql code out of your daemon and put it in a separate
python script which is started from .bash_logout
 
Old 06-27-2005, 09:41 AM   #4
thinkgeek
LQ Newbie
 
Registered: Jun 2005
Posts: 15

Original Poster
Rep: Reputation: 0
but i want to control the entire process centrally using a daemon.

is there no signal which the user sends before logout?
how the system knows that the user is about to logout?

prior to the logout of every user connected to NIS server i want to
perform some update activities.

thinkgeek
 
Old 06-27-2005, 11:16 AM   #5
frandalla
Member
 
Registered: Oct 2003
Location: Tokyo - Japan
Distribution: Slackware
Posts: 348
Blog Entries: 1

Rep: Reputation: 37
I think I found what we need =)
(http://www.cactus.org/~dak/shellscript.html)
Let's google guys!

Process Handling

*
Signals

Name Number Control Character
o EXIT 0 Used to trap exiting script
o HUP 1 Logout
o INT 2 Control-C
o QUIT 3 Control-\
o KILL 9 can not be ignored or trapped
o TERM 15 Default kill
o TSTP 24 Control-Z

*
Traps

o trap "" signal-list Ignore signal
o trap "cmds" signal-list Execute commands if signal is caught
o trap signal-list Reset signal to original condition
o trap : signal-list (undocumented) ignore signal, pass to child
Signal are normally not passed to subprocesses
o Examples
trap 'rm tmpfile; exit' 0 1 2 #remove tmpfile on exit, logout, interrupt

trap "echo 'You hit Control-C'" INT
while true ; do
sleep 60
done
o Example parent child process
#!/bin/bash #parent
echo parent running
trap 'echo parent exiting; exit' 0
trap :2
child
sleep 1000

#!/bin/bash #child
echo child started. pid is $$
trap 'echo child got signal 2; exit' INT
sleep 1000
 
  


Reply



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
squid stops due to signal 6 and signal 25 simplyrahul Linux - Software 3 05-28-2011 01:05 AM
On gnome / x logout run "logout" ?? once here Linux - Software 1 01-09-2004 02:53 PM
Capture support for dvd and video capture in linux is it even going to be real ever? maximalred Linux - Distributions 3 07-06-2003 07:29 PM
Signal 6: Unknown Signal <=> Error with MAYA4.X under Linux SOLVED!!!! Faeroon Linux - Software 9 05-09-2003 01:57 PM
Signal: 6 (Unknown Signal) - Problems running a program Faeroon Linux - Software 86 01-14-2003 12:08 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:22 PM.

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