Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Running startx automatically...

Tue Sep 30, 2014 8:10 pm

Note: This is not a "How do I?" post, but rather a "Why does it do that?" post.

Since pre-historical times, I have been using a little trick to automatically launch the GUI on Linux systems. I put code like:

Code: Select all

[ $(tty) = /dev/tty2 ] && exec startx
In one of the startup bash files - say, .profile.

This has always worked on regular Linux, but today I decided to give it a shot on the Pi (Raspbian).
Note, BTW, that when combined with putting "-a pi" in the /etc/inittab line for tty2, you get an automated launch of the GUI without needing to manually logging in.

However, when I did this on the Pi, it went into an infinite loop, launching zillions of copies of "xinit" and never displaying the GUI. In fact, the console was locked up (couldn't do any Ctrl/Alt/Anything) - and recovery was only possible by ssh'ing in to:
  • 1) Undo the change in the .profile
    2) killall -v xinit
And the "killall" kills a lot of processes!

After fiddling with this for a while (repeating it several times to be sure it really was doing this), I eventually changed it to:

Code: Select all

[ $(tty) = /dev/tty2 ] && {
    pidof xinit || exec startx
    }
And now all is well. The code above ensures that the "exec starts" only runs if there is no "xinit" process already running. A kludge, but it works.

My question is: Why does this happen?

I'm guessing it has something to do with the complicated GUI that runs on the Pi - a complicated shell that launches lots of processes and stuff - probably something along the way is running the .profile again. I assume if I stripped it away and went back to using, say, twm, as my window manager, the problem would go away. Still, I'd like to know what piece of software is the culprit here.

Anyone know?
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

elatllat
Posts: 1337
Joined: Sat Dec 17, 2011 5:05 pm

Re: Running startx automatically...

Wed Oct 01, 2014 3:29 am

ps -efH

Might provide insight.
SBC with 32GB RAM: https://hardkernel.com

FAQ : https://raspberrypi.stackexchange.com

Unanswered: https://www.raspberrypi.org/forums/search.php?search_id=unanswered

Return to “Raspberry Pi OS”