Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: sudo sh -c "pkill Xorg && systemctl suspend" but it doesn't kill Xorg

68 views
Skip to first unread message

Kenny McCormack

unread,
Sep 27, 2022, 9:01:32 AM9/27/22
to
In article <tguj5q$1nic$1...@dont-email.me>,
Ottavio Caruso <ottavio2006...@yahoo.com> wrote:
>Hi,
>
>Debian Stable + latest bash.
>
>If I issue:
>
>$ sudo pkill Xorg
>
>the system will kill Xorg and present me with a new login screen (LightDM)
>
>However :
>
>$ sudo sh -c "pkill Xorg && systemctl suspend"
>
>Just suspends my laptop.
>
>If I wake the laptop, it resumes without killing Xorg.

You probably need a sleep in there, to give Xorg time to go away, before the
OS is suspended.

--
Shikata ga nai...

Kenny McCormack

unread,
Sep 27, 2022, 10:16:40 AM9/27/22
to
In article <tgus76$2180v$1...@news.xmission.com>,
...
>>$ sudo sh -c "pkill Xorg && systemctl suspend"
>>
>>Just suspends my laptop.
>>
>>If I wake the laptop, it resumes without killing Xorg.
>
>You probably need a sleep in there, to give Xorg time to go away, before the
>OS is suspended.

I should add that you also probably don't need "sudo" at all.

Like you, I used to use "sudo" to kill the Xorg process (which usually runs
as root - although not necessarily - see below), but the fact is that you
can usually kill some other process - downstream of Xorg - that is running
as you (and thus won't need sudo), and this will cause the Xorg process to
shutdown in due time. The process that I usually kill is called "lxsession".

BTW, off-topic in shell newsgroup. Probably more of a "Linux type" question.

Footnote: Hyper-modern versions of Linux now run the X process as the user,
rather than as root. You can recognize these hyper-modern versions by the
fact that the X process ends up running on, say, tty1, instead of, say, tty7.

Footnote 2: There should be a way to more programatically exit the X
process, rather than having to mess around with killing processes...

(In the previous sentence, the word "should" can (and should) be
interpreted in multiple ways)

--
https://en.wikipedia.org/wiki/Mansplaining

It describes comp.lang.c to a T!

Kaz Kylheku

unread,
Sep 27, 2022, 2:12:32 PM9/27/22
to
On 2022-09-27, Ottavio Caruso <ottavio2006...@yahoo.com> wrote:
> If I wake the laptop, it resumes without killing Xorg.
>
> What am I doing wrong?

The default signal sent by kill and pkill is SIGTERM. That's a catchable
signal; it's not guaranteed to be fatal. An application can ignore
the signal, catch it and do nothing, or catch it and precipitate into
an orderly shutdown --- executing millions of instructions more code
until it terminates. Even if the program is designed to catch SIGTERM
and terminate, something could go wrong between those two events
to thwart the developer's good intentions, like the program getting
stuck somewhere, waiting for some external event that never comes
or getting into an infinite loop.

To kill something for sure, you must use the SIGKILL signal.

A reasonable middle ground is to use SIGTERM first, then wait for some
reasonable amount of time so the application has a chance to do a
graceful shutdown, and then SIGKILL.

"kill" is the name of a system library function, and of a command.
But what that function and command do isn't killing; they are signal
sending functions that have been misnamed by Unix.

kill(pid, sig); // send signal number sig to process pid.

Sending a signal results in termination only when that is the
effect of the specific signal which is used.

You can't take words too literally in computing. E.g. "print" rarely
does anything with paper any more; "opening" a file is nothing like a
opening a door, job position or a bank account, etc.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

Kenny McCormack

unread,
Sep 28, 2022, 6:10:27 AM9/28/22
to
In article <th16bp$bbii$3...@dont-email.me>,
...
>> I should add that you also probably don't need "sudo" at all.
>
>$ pkill Xorg
>pkill: killing pid 442065 failed: Operation not permitted

Reading is obviously not your strong suit.

--
Hindsight is (supposed to be) 2020.

Trumpers, don't make the same mistake twice.
Don't shoot yourself in the feet - and everywhere else - again!.

Jalen Q

unread,
Mar 5, 2023, 8:01:16 PM3/5/23
to
> Don't shoot yourself in the feet - and everywhere else - again!.gdtdtddyddgf
Message has been deleted

Jalen Q

unread,
Apr 11, 2023, 11:18:35 PM4/11/23
to
Message has been deleted
Message has been deleted
0 new messages