2

I've set up automatic login and made X auto start like this:

.bach_profile:

sh ~/startup.sh

startup.sh:

#!/bin/sh

if [ -e "/tmp/X0-lock" ];
        then
                echo "X has already been started"
        else
                /usr/bin/startx
fi

.xinitrc:

xset s off -dpms &
ratpoison &
~/userapp/demo

while [ -f /userapp/demo/.keepalive ]
do
        ~/userapp/demo
done

sudo /sbin/reboot

This works great in the sense that it starts X (with ratpoison) and my application, and it also restarts the application unless that .keepalive file is missing (which is something defined by the application).

The problem however, is that on the Raspberry version of Debian Wheezy,
there is no X0-lock file in the /tmp/ directory to indicate X has started so the check in startup.sh
will always return false and an attempt will be made to start X every time.

How can I check if X has already been started on the Raspberry?

2

the command pidof X will return if the PID of X if it is running. If it returns a number then you can tell it is running. From there it is simply a matter of placing it in your bash script like so:

X=$( pidof X )
if [ ${#X} -gt 0 ]
then
        echo "X has already been started"
else
        /usr/bin/startx
fi

This bash script was mostly scraped off this Stack Overflow Question.

  • What does the '4' stand for in this case? – TimothyP Mar 20 '13 at 7:53
  • The comparison in the example was invalid as the pid will always be a different number, so I updated your answer so that the comparison is ' -gt 0' --> Greater than 0. Now it works, thank you. – TimothyP Mar 20 '13 at 8:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.