WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: One-Liner to restart X?  (Read 2459 times)

Offline Misalf

  • Hero Member
  • *****
  • Posts: 1702
One-Liner to restart X?
« on: June 28, 2016, 10:38:29 AM »
Hi there!

I'm searching for an one-liner to restart X, that I can then, for example, add to my Window Manager menu or execute via key press.

I was hoping for something like this to work
Code: [Select]
nohup { kill $(cat /tmp/.X${DISPLAY:1:1}-lock) ; sleep 2 ; startx ; }

I tried several combinations using  {} , () , sh -c ""  and  & , but couldn't yet get it to work, since either the command dies together with X or X won't die at all.

Anyone has an idea?
Download a copy and keep it handy: Core book ;)

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11702
Re: One-Liner to restart X?
« Reply #1 on: June 28, 2016, 10:58:29 AM »
Hi Misalf
Instead of a one liner maybe break the problem down into two pieces. Create a script with the required commands
called  restartX. Place it in  ~/.local/bin  so it's included by the  $PATH  environmental variable. Your one liner will now
be  restartX.


Offline andyj

  • Hero Member
  • *****
  • Posts: 1036
Re: One-Liner to restart X?
« Reply #2 on: June 28, 2016, 11:04:21 AM »
A while true loop in .profile and Ctrl-Alt-Bksp to kill X won't work?

Offline Misalf

  • Hero Member
  • *****
  • Posts: 1702
Re: One-Liner to restart X?
« Reply #3 on: June 28, 2016, 11:14:29 AM »
Thanks Rich, I'll see if that can fit my needs. The reason I'm asking for a one-liner though, is that I would like it to be as portable as possible - user (and maybe distro) independent.

andyj, thanks but no (see above). Also, if I get it right, this would prevent the user from using the Linux console.
Download a copy and keep it handy: Core book ;)

Offline Misalf

  • Hero Member
  • *****
  • Posts: 1702
Re: One-Liner to restart X?
« Reply #4 on: June 28, 2016, 11:39:41 AM »
Yeah, of course. Just when I think i can't get it working...
Code: [Select]
{ kill $(cat /tmp/.X${DISPLAY:1:1}-lock) ; sleep 2 >/dev/tty0 ; startx >/dev/tty0 ; } &

Is  /dev/tty0  always available?
Download a copy and keep it handy: Core book ;)

Offline Misalf

  • Hero Member
  • *****
  • Posts: 1702
Re: One-Liner to restart X?
« Reply #5 on: June 28, 2016, 11:57:18 AM »
This might be better
Code: [Select]
{ kill $(cat /tmp/.X${DISPLAY:1:1}-lock) && { sleep 1 ; startx ; } >/dev/tty0 ; } &
« Last Edit: June 28, 2016, 12:01:31 PM by Misalf »
Download a copy and keep it handy: Core book ;)