There is a difference between at boot and at login. This may be somewhat obscured in Raspbian if you use autologin, because right after booting finishes a login will automagically occur.
Booting is something the system does when started irregardless of whether anyone is going to log in afterward. Boot services are by default owned by the superuser (root
), although this ownership is often switched to de-escalate privileges, making the service less of a security risk. The activities started at boot run in the background -- except for login consoles (and/or GUI logins, aka. "display managers"). Note the system can be configured to run something else in the foreground instead, but this is the norm for a multi-purpose desktop style system. Also note there does not have to be anything run in the foreground, which is the case for a headless system, with no physical HID (human interface device such as a keyboard or monitor).
"Foreground" is a little subjective. In one sense it refers to the perspective of a user. In another (compatible) sense, it refers to a relationship between a parent and child process -- a foreground process will block its parent until it completes or goes into the background.
Note that all processes have a parent, except for the first one, init, which is responsible for starting most processes at boot. On Raspbian init is systemd
. If the parent of a process dies, any children which survive will be adopted by init.
Login is something a user does to start an individual session with the system. This may be anytime after the system has more or less finished booting.
I have tried adding the link to the rc.local folder
This is no good for what you want, which is to start something inside a login session. /etc/rc.local
is a catch-all boot script intended to run things in the background (unless they can be completed very quickly).
I have tried adding sudo python3 /home/pi/Desktop/GUI.py
.bashrc
Soon has I open terminal these programs will open.
Yes because .bashrc
is a configuration script for an interactive shell. The shell is the program which gives you a command-line prompt. From man bash
(the INVOCATION section):
When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists.
When you open a GUI terminal, it starts a new (interactive, non-login) shell, which explains the behaviour you are experiencing. It is sometimes suggested to instead use .profile
(or /etc/profile
, or something in /etc/profile.d
), since this is the shell configuration for an interactive login shell (a login shell is the shell first opened after you complete a text console based login). However, this is not a great idea since if you are using a GUI, there is never a login shell (although some desktop environments will run .profile
to make up for this. It is probably a bad place to start anything GUI oriented since it applies to remote text logins (e.g., ssh
) as well (although you could probe the context conditionally to deal with this).
With regard to running something just once at the start of a GUI login session, this is specific to the DE ("desktop environment") you are using. The current default on Raspbian is PIXEL, a spin-off of LXDE.