LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 06-17-2009, 06:05 AM   #1
logforlinux
LQ Newbie
 
Registered: Feb 2009
Posts: 14

Rep: Reputation: 0
Question How to know if a Linux machine is locked programmatically?


Hi,

In my program, I am tyring to find whether a linux machine is screen locked or not, but i am not finding any suitable command to do this.

Please help me to know whether a machine is screen locked or not, any command ?



Thanks,
Prashant
 
Old 06-17-2009, 08:21 AM   #2
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,925
Blog Entries: 44

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
Hi,

Welcome to LQ!

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.
 
Old 06-17-2009, 09:34 AM   #3
logforlinux
LQ Newbie
 
Registered: Feb 2009
Posts: 14

Original Poster
Rep: Reputation: 0
Ok..
So here is the story

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?

Thanks,
Prashant
 
Old 06-17-2009, 10:47 AM   #4
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
Quote:
Originally Posted by onebuck View Post
Hi,

Welcome to LQ!

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?
 
Old 06-18-2009, 05:55 AM   #5
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,925
Blog Entries: 44

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
Hi,

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.
 
Old 06-18-2009, 06:53 AM   #6
fpmurphy
Member
 
Registered: Jan 2009
Location: /dev/ph
Distribution: Fedora, Ubuntu, Redhat, Centos
Posts: 299

Rep: Reputation: 62
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.

Last edited by fpmurphy; 06-18-2009 at 06:54 AM.
 
Old 06-18-2009, 06:55 AM   #7
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
Quote:
Originally Posted by onebuck View Post
Hi,

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.
 
Old 06-18-2009, 07:10 AM   #8
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
I too can't see any problems with this request.

The man page for xscreensaver-command has a perl script example that does it:

http://manpages.ubuntu.com/manpages/...command.1.html
 
Old 06-18-2009, 08:28 AM   #9
noctilucent
Member
 
Registered: Jun 2009
Distribution: slackware
Posts: 123

Rep: Reputation: 34
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.
 
Old 06-22-2009, 04:59 AM   #10
logforlinux
LQ Newbie
 
Registered: Feb 2009
Posts: 14

Original Poster
Rep: Reputation: 0
Process named 'kdesktop_lock' ....

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?


What abt GNOME?

Thanks all of you for this discussion.
 
  


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
How to shutdown Linux programmatically darwins Linux - Newbie 2 12-24-2008 08:19 PM
How to press Alt + F1 keys programmatically in Linux dipk_23 Programming 4 05-10-2007 01:01 AM
Locked red hat machine by user ajdowntown Red Hat 2 11-01-2006 05:12 PM
Rebooting Locked up Linux Machine? matt80 Linux - General 6 05-19-2004 09:35 AM
machine accounts locked monc Linux - Networking 0 02-12-2004 07:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:08 AM.

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