|
-
July 20th, 2006, 11:42 AM
#1
OSX / BSD / Linux - Knowing when a user loggs out
I have a generic C++ program that normally constantly runs. However, I want the program to stop when the current user logs out.
This program is running on OS X, which is very close to BSD and is similar to Linux. Is there some event or signal I can listen for to know when the current user is logging out so my program can exit?
-
July 20th, 2006, 12:52 PM
#2
Re: OSX / BSD / Linux - Knowing when a user loggs out
I don't know how on OSX, but generally on unixes, if the program is run by user on the console (even in background), then it gets SIGHUP signal (or SIGINTR or other depending on the specific system) when the session is terminated.
If the program is run independently, you can also get information about logged in users using UTMP (see utmp.h manpage) functions. This is however not POSIX standard, just BSD/SysV.
-
July 20th, 2006, 01:17 PM
#3
Re: OSX / BSD / Linux - Knowing when a user loggs out
Ok. What is the signal API? I am do not know unix / linux very well. I know that a lot of the time the name of the function doesn't sound intuitive. That makes it very hard to search the API to find a function that does X.
-
July 20th, 2006, 01:34 PM
#4
Re: OSX / BSD / Linux - Knowing when a user loggs out
You need to call 'sigaction' to register handler function which get executed when the specific signal is received:
Code:
#include <signal.h>
static void signalhandler(int signum)
{
// ...
}
...
struct sigaction sa;
sa.sa_handler = signalhandler;
...
sigaction(SIGHUP, &sa, NULL); // returns -1 on error
The exact API may differ on OSX though.
-
July 20th, 2006, 03:51 PM
#5
Re: OSX / BSD / Linux - Knowing when a user loggs out
Thanks. I just need to find the right signal It seems. Apparently SIGHUP doesn't get fired when you log out on Mac OSX.
SIGTERM and SIGINT do not come either. I wonder if any signal is even sent when you log out.
Last edited by DeepT; July 20th, 2006 at 03:57 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|