You are not logged in.

#1 2007-11-23 12:14:40

Ashren
Member
From: Denmark
Registered: 2007-06-13
Posts: 1,226
Website

How do I restart X from the console or from bash script?

I have searched with google, but can't find any answers not involving gdm or xdm. I need this because I'm writing a simple script that compiles and installs dwm and then restarts x.

Thanks.

Offline

#2 2007-11-23 12:26:42

bluePoet
Member
From: Düsseldorf, Germany
Registered: 2006-01-09
Posts: 38
Website

Re: How do I restart X from the console or from bash script?

startx will do the trick wink

Offline

#3 2007-11-23 12:41:46

Ashren
Member
From: Denmark
Registered: 2007-06-13
Posts: 1,226
Website

Re: How do I restart X from the console or from bash script?

Ok, let me rephrase..
I did try every possible (I could think of anyway) combination of pkill, killall X and startx, but to no avail.

How do I restart X from a virtual console? As far as I understand startx runs a new instance of X.

Typing startx prints:

xauth:  creating new authority file /home/edgar/.serverauth.15607

Fatal server error:
Server is already active for display 0
    If this server is no longer running, remove /tmp/.X0-lock
    and start again.


Couldnt get a file descriptor referring to the console

This is probably all very simple.

Offline

#4 2007-11-23 15:07:36

ks1
Member
From: Atlanta, Georgia
Registered: 2006-03-26
Posts: 62
Website

Re: How do I restart X from the console or from bash script?

You could write a script that gets the PID of X and then kills the process and startx.

manually just
ps aux|grep X then kill -9 PID_OF_X
then startx

Offline

#5 2007-11-23 15:21:39

buttons
Member
From: NJ, USA
Registered: 2007-08-04
Posts: 620

Re: How do I restart X from the console or from bash script?

ks1 wrote:

You could write a script that gets the PID of X and then kills the process and startx.

manually just
ps aux|grep X then kill -9 PID_OF_X
then startx

You mean...

sudo kill `pidof X`

Remember that X is run as root, so this command will also need to be run as root.  You can give yourself NOPASSWD for the kill command with sudo if you like.

Last edited by buttons (2007-11-23 15:23:07)


Cthulhu For President!

Offline

#6 2007-11-23 16:53:28

Ashren
Member
From: Denmark
Registered: 2007-06-13
Posts: 1,226
Website

Re: How do I restart X from the console or from bash script?

Thanks for your comments, but they don't solve my problem, though. If kill X in a bash script, the script gets killed with X because it is running in a virtual terminal, and hence is unable to run startx. Or am I totally wrong?

I think I'm learning the meaning of a virtual console. smile

Offline

#7 2007-11-23 17:13:17

buttons
Member
From: NJ, USA
Registered: 2007-08-04
Posts: 620

Re: How do I restart X from the console or from bash script?

Just out of curiosity, why don't you have X respawning?  I also using tiling WMs and before I discovered Xmonad (which lets you reload configs with a keystroke) all I had to do was kill X and there was my desktop a second or two later.

You might try sudo kill `pidof X` && startx, but I have a feeling that won't work either.


Cthulhu For President!

Offline

#8 2007-11-23 17:25:39

lilsirecho
Veteran
Registered: 2003-10-24
Posts: 5,000

Re: How do I restart X from the console or from bash script?

Does ...ctl alt F7... help?


Prediction...This year will be a very odd year!
Hard work does not kill people but why risk it: Charlie Mccarthy
A man is not complete until he is married..then..he is finished.
When ALL is lost, what can be found? Even bytes get lonely for a little bit!     X-ray confirms Iam spineless!

Offline

#9 2007-11-23 17:47:41

Ashren
Member
From: Denmark
Registered: 2007-06-13
Posts: 1,226
Website

Re: How do I restart X from the console or from bash script?

lilsirecho, no it does nothing.

buttons, sudo kill 'pidof X' && startx did work with xdm enabled (I still had to login again, though). The reason I don't use respawn is that I don't like display managers. Is there any way to circumvent them and still have the respawn feature? I want to restart dwm without typing in anything, besides the name of my script.

Thanks..

Offline

#10 2007-11-23 17:49:29

flx
Member
Registered: 2006-01-06
Posts: 9

Re: How do I restart X from the console or from bash script?

Ashren wrote:

I have searched with google, but can't find any answers not involving gdm or xdm. I need this because I'm writing a simple script that compiles and installs dwm and then restarts x.

Thanks.

You can just run dwm in a loop in your .xinitrc :

until dwm; do    
    sleep 1
done

Now if you kill dwm it will automatically restart. X isn't affected, so all your app windows will still be there.
I usually do a:

make && killall dwm && cp dwm ~/bin

to switch out the dwm binary.

Offline

#11 2007-11-23 17:54:25

buttons
Member
From: NJ, USA
Registered: 2007-08-04
Posts: 620

Re: How do I restart X from the console or from bash script?

Ashren wrote:

lilsirecho, no it does nothing.

buttons, sudo kill 'pidof X' && startx did work with xdm enabled (I still had to login again, though). The reason I don't use respawn is that I don't like display managers. Is there any way to circumvent them and still have the respawn feature? I want to restart dwm without typing in anything, besides the name of my script.

Thanks..

Absolutely.

Relevant parts of /etc/inittab:

id:5:initdefault:
x:5:respawn:/bin/su buttons -l -c "/bin/bash --login -c startx >/dev/null 2>/home/buttons/.xsession-errors"

"buttons" is of course my login name, and I prefer to have my errors go to a logfile in my home directory, which many display managers do by default.  Or at least GDM.


Cthulhu For President!

Offline

#12 2007-11-23 18:07:37

Ashren
Member
From: Denmark
Registered: 2007-06-13
Posts: 1,226
Website

Re: How do I restart X from the console or from bash script?

Brilliant! That worked beautifully. Thanks flx.

And welcome onboard.

Buttons, very interesting and your example will no doubt work as well. I learned a lot here. In general I learn a lot by using Arch and from this board and its simply great.

Offline

#13 2007-12-07 00:51:29

egates
Member
From: CMU, Pittsburgh, PA
Registered: 2007-10-22
Posts: 12
Website

Re: How do I restart X from the console or from bash script?

What I generally do after compiling and installing is quit dwm (there's a keybinding for it) and then restart it.  This way all the applications you had open, remain open.

-Evan

Offline

Board footer

Powered by FluxBB