For systems running KDE 4.x that will be
qdbus org.freedesktop.ScreenSaver /ScreenSaver Lock
For Ubuntu / Gnome:
qdbus org.gnome.ScreenSaver /ScreenSaver Lock
Qdbus as written above, just sends a message on the message bus, which the screen-locker receives. The command will however lock the screen. qdbus just asks nicely "will someone lock the screen please?"
The advantage of using qdbus, is that it is supported on other platforms than KDE. The text below works for KDE4 only.
Now watch and learn :o)
To figure this out in a little more detail, a bit of bash trickery is required:
- list all processes while unlocked
- lock the screen
- wait a moment to get the screen locked
- then list the processes while locked
- find the differences between the output of both commands
diff <( cmd1 ) <( cmd2 )
The command line:
diff <( ps -ef ) <( qdbus org.freedesktop.ScreenSaver /ScreenSaver Lock; sleep 1; ps -ef )
< jhendrix 17088 16352 0 21:11 pts/4 00:00:00 /bin/bash
< jhendrix 17091 17088 0 21:11 pts/4 00:00:00 ps -ef
< jhendrix 17092 17089 0 21:11 pts/4 00:00:00 qdbus org.freedesktop.ScreenSaver /ScreenSaver Lock
> jhendrix 17093 2801 11 21:11 ? 00:00:00 /usr/lib/kde4/libexec/kscreenlocker --forcelock
> jhendrix 17095 17093 11 21:11 ? 00:00:00 kblankscrn.kss -root
> jhendrix 17099 17089 0 21:11 pts/4 00:00:00 ps -ef
This narrows down the list of potential commands to lock the screen, doesn't it?
Now the answer to your question is simple: To lock the screen from the commandline use:
/usr/lib/kde4/libexec/kscreenlocker --forcelock the blankscrn.kss is a child process of kscreenlocker, so kscreenlocker is the one to run.
To view the command syntax:
What it does? It basically draws a big black window that covers the whole screen and it forces it to be on top of everything. It catches all keystrokes and pops up a login dialog.
Finally which package does it come in (kde-workspace-bin)?
$ dpkg -S /usr/lib/kde4/libexec/kscreenlocker