开发者

Native events fired when a user logs in to Linux or Mac OS

I am developing a background service which needs to run on Windows, Linux, Mac OS and Solaris. The service is very simple and is to be used to track students logging in and out of university computers. I have almost finished the Windows imple开发者_JS百科mentation of the service.

I have invested in a number of books around native application / service development for Linux and for Mac OS. I can learn the fundamentals from those but there is something more specific which I need which seems to be much too specific a topic to be covered by the books I have.

The question is about native events on Linux and Mac OS which a background service can register to respond to when a user logs in and out. I would also need to get the user id of the user who logged in or out (which should be more straightforward once the first item is solved).

Being new to native development for Linux and Mac OS I could really benefit from some help from more experience developers for these platforms. A friend suggested that PAM can be used to register to be notified of such events. Is this true?

I may not need to know the exact details of everything I have to do but it would be good to know what native events / mechanisms are available to achieve this (if any but I am hoping there are because Windows certainly has them).

Kind Regards

Carl


On Mac OS X, you can define LoginHook and LogoutHook scripts to run as part of the login/logout process; see Apple's documentation and Mike Bombich's notes and examples. Another possibility would be to create a LaunchAgent -- the main difference would be that a LaunchAgent will run as the user, inside their login session, while LoginHook and LogoutHook scripts run as root. Most of Apple's docs about this concentrate on LaunchDaemons, but LaunchAgents are very similar except that they run within user login sessions, while LaunchDaemons run as root (but independently of login sessions, making them unsuitable for what you want).


This is already tracked for unix/linux/mac. Look at the command line program "last"... man last.


On recent Linux distros, you might look into ConsoleKit, but for older ones, and Unix in general, I don't know of any way to be notified in realtime, short of writing your own code to insert into the system, such as a PAM module on OS'es supporting PAM.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜