How to know if a Linux machine is locked programmatically?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a program which gets loaded during system boot and remains up till the shutdown/reboot/logout. I want to handle a case where the user logs in and then lock the computer. If locked, execute PATH1 and if unlocked then execute PATH2. The execution of program will be different based on the system lock and unlock.
So is there any way (command) to find out whether the system is Screen lock and unlock?
By the LQ Rules, we should not discus or present the means to crack a machine. Your post is on the fringe.
I think your speaking of the WM lock screen function for some desktops. That too can be considered cracking.
What exactly is your purpose for the program? Please be more specific.
While the OP's explanation of what he's trying to do is still pretty vague, I can think of serveral valid reasons why a program may want to be notified of a screen lock or unlock event. A media player playing a video file might want to pause itself for example and then resume on a subsequent unlock event, or other monitor type program may want to suspend window redraws/updates to save CPU when there's no one sitting in front of the screen to view their output. Polling the current state of the lock I can see less reasons for, but I'm sure there could also be valid reasons to do that.
I don't see how being able to poll the state of a locked desktop from a program would aid a cracker. their program would already be running.
Anyway, I don't know what facilities are available to query/monitor this programatically but it sounds like it'd be in the realm of desktop integration, so perhaps there's something sent over dbus?
I can! For instance in a LAB environment were you lock screens while collecting data. Or locking it so colleagues won't have access while your away from the station...
Other examples can be presented. When the screen or machine is locked it is done for the reason of securing it from access.
Do a web search for "dbus screen lock". If your particular version of GNU/Linux supports HAL and DBUS, you can detect whether a screen is locked via HAL or DBUS.
I can! For instance in a LAB environment were you lock screens while collecting data. Or locking it so colleagues won't have access while your away from the station...
Other examples can be presented. When the screen or machine is locked it is done for the reason of securing it from access.
What the OP is trying to achieve here isn't clear however, if I understood the question correctly, he was asking only how a program can be notified (or query) whether the screen is locked or unlocked. I didn't see any mention of circumvention of that locking and I don't see how being able to query this 'state' information is a threat to the scenarios you suggest above.
Anyway, the guy's not responded again, so I guess it doesn't matter.
What happens if you are locking your screen with xlock? xlockmore? slock? noctilucentsflufflyscreenlock? How would you go about detecting it then? As far as I can tell [by -briefly- inspecting some source code] X screen locking is accomplished by a program which spawns an X window, maximizes it and 'intercepts' [in need of a better word] key presses, etc. [X events].
Last edited by noctilucent; 06-18-2009 at 08:31 AM.
I have observed on KDE, when the computer is locked, one process named 'kdesktop_lock' starts running, so i chan check for this process and can decide whether the current machine running KDE is locked/unlock.
Should I rely on 'kdesktop_lock' process to find the lock/unlock state of a machine?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.