简体   繁体   中英

Stop Raspberry Pi from running program at boot

I was trying to figure out how to run a program at boot, but after realizing this program is an infinite loop, I have no way of getting out, or back to the terminal. Right when I give the Pi power it just goes right to the program on a black background. I don't remember exactly what I did to make it run at boot, I believe I just added some code in a place right above something that said "exit 0" and below something that says "esac". I don't remember the command that even got me there. (I am new to the Pi and Python and have just been playing around..unsucessfully.)

If anyone could help me either delete this program or get me to be able to edit it so I can fix the infinite loop that would be great. I'd rather not have to completely over-write the sd card with a fresh raspbian. But like I said I can't do anything at boot, and Ctrl + C doesn't do anything nor Ctrl + Alt + Delete.

EDIT: When I put the SD card in my computer, I see a list of 11 files: bootcode cmdline config fixup fixup_cd issue kernel kernel_cutdown kernel_emergency start.elf start_cd.elf

None of these mean anything to me...

Update: Looks like I failed to get that you want to interrupt the running bootprocess and stop the script.

The simplest idea would be to turn of the pi, unplug the sd card and plug it into your desktop, (re)move the script and boot again.


Processes spawned during boot are stored in scripts in /etc/init.d/... . These scripts are called by the init process, the first process on a Linux machine (PID:1)

But init starts not all scripts in /etc/init.d . This depends on the run level. On a debian system there are 7 run levels.

For every run level there is a folder called like:

/etc/rc0.d
...
/rc6.d

in which are softlinks to scripts from /etc/init.d are stored.

To remove a script from being executed on every boot you'll delete all links from that folders. Usually on debian systems this is done using the update-rc.d tool:

update-rc.d NAME_OF_INIT_SCRIPT remove

You should also have a look at the file /etc/rc.local

Alt + PrintScn + k用于终止从rc.local运行的进程

You can use the cmdline.txt. First, add or modify the cmdline.txt file on your sd card. Add "init=/bin/sh", then restart your Pi, and you can see a command line prompt. Type 'sudo nano /etc/rc.local' to edit the file, and comment or delete the line containing the error. After that restart.

I had exactly the same issue, couldn't quit the process using CTRL+C. I edited the cmdline.txt like stated above, but then the pi didn't load the necessary usb drivers for my keyboard.

So eventually I logged in over SSH to the pi, and modified my rc.local file that way.

I had the same problem as explained at the beginning of this Post. My Python app was caught in an endless loop.

I tried the Ctrl + Alt + F2 Command as recommended in many posts found in Internet without any terminal window being open. Apparently, after many other trials and reboots I saw a glimpse of a Terminal window each time the loop of my application restarted. It was impossible to catch anything until I started recording the screen using the slow motion video of my mobile phone and, yes, a terminal window with the Linux prompt was active, and able to accept keyboard entries.

All I did was (almost blindly) editing the culprit file with the

sudo nano filename command 

and entering some characters in order to actually corrupt such file, saving and closing it, a rebooting the Pi. At the end of the boot, the file produced an error but the system kept ready to operate.

I was then able to fix the bug in a normal way. It hope this may be useful to others. In my case it spared me of burning a new Raspbian and losing all my previous work.

I got myself stuck in exactly the same problem. Luckily I had the ssh enabled, apparently this is disabled by default on Raspbian Jessie, so this may not work for all.

The exit 0 is the line in /etc/rc.local where you would have added in the script that is now running in a continuous mode. If you can ssh into the Pi using Putty and the Pi's IP address then

sudo nano /etc/rc.local

Scroll down to the bottom of the file and remove the offending program, then sudo reboot

They way to prevent this issue from happening is to add an & (ampersand) to the end of the line to fork the process and run it as a separate process like so

python /home/pi/myscript.py &

as specified in https://www.raspberrypi.org/documentation/linux/usage/rc-local.md

The ampersand allows the command to run in a separate process and continue booting with the process running.

在我的情况下工作组合“Alt”+“F4”,它停止当前会话并打开登录屏幕

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM