thenorm
Posts: 11
Joined: Mon Feb 24, 2014 2:05 am

Stopping a program launched by rc.local

Tue May 09, 2017 1:13 am

If I start a program ( with an "&" appended) from rc.local how can I stop it from the command line?

SurferTim
Posts: 1769
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Stopping a program launched by rc.local

Tue May 09, 2017 2:19 am

You might try getting the pid of the program and using kill.
https://www.digitalocean.com/community/ ... s-in-linux

User avatar
DougieLawson
Posts: 36179
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Stopping a program launched by rc.local

Tue May 09, 2017 10:28 pm

sudo kill -term $(pidof programnamegoeshere)

In general it's much better to write a systemd service file for things you want to start and control. Here's an example that gets a program that reads a BMP180 sensor and write the data to an SQLite table running.

Code: Select all

[email protected] ~ # cat /etc/systemd/system/bmp180.service
[Unit]
Description=BMP180 server

[Service]
ExecStart=/srv/bmp180/bmp180.sqlite.py
Restart=always
User=pi
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=BMP180

[Install]
WantedBy=multi-user.target

[email protected] ~ #
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Return to “Troubleshooting”