hatrabbit
Posts: 7
Joined: Wed Feb 14, 2018 11:35 pm

What is commanding this .py to run?

Tue Feb 20, 2018 3:46 am

I wanted a python scrip to run at startup so I edited '/etc/rc.local' to include the line:

python /home/pi/program.py &

It worked and the program was running, but when I entered 'ps -aef | grep python' in Terminal I saw that there were two instances of program.py running, one at the user level and one at root. I went back and edited '/etc/rc.local', removing the line I had added. Now the program starts every time my Pi boots, but only at the user level, but there's nothing in rc.local to tell it to start. Where is the command to run coming from?

User avatar
topguy
Posts: 5786
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: What is commanding this .py to run?

Tue Feb 20, 2018 11:37 am

You have added it somewhere else too, but forgotten it.

Check your ".bashrc" file in "/home/pi" for example.

n67
Posts: 938
Joined: Mon Oct 30, 2017 4:55 pm

Re: What is commanding this .py to run?

Tue Feb 20, 2018 12:26 pm

As I recommended in a similar thread posted about a week ago, the way to fix this is to delete or rename (same thing for our purposes) the script, then reboot, and watch carefully for error messages.

You should be able to figure out what part of the system is trying to run it, but failing to do so.

BTW, it might be in cron (also known on the forum as "crontab -e"), in which case you will have to check the syslog (and similar) file(s) in /var/log.

Also, another thing to try - before you delete/rename the file, that is, while it is still running, figure out its pid (via the ps command that you've already mastered) and then do:

less /proc/<pid>/status

This will tell you (among other things) the parent process ID of the Python script - and this may help determine who started it.
"L'enfer, c'est les autres"

G fytc hsqr rum umpbq rm qyw rm rfc kmbq md rfgq dmpsk:

Epmu Sn!

J lnacjrw njbruh-carppnanm vxm rb mnuncrwp vh yxbcb!

User avatar
topguy
Posts: 5786
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: What is commanding this .py to run?

Tue Feb 20, 2018 1:52 pm

"ps -ef" also print process pid and pid of parent process.

hatrabbit
Posts: 7
Joined: Wed Feb 14, 2018 11:35 pm

Re: What is commanding this .py to run?

Tue Feb 20, 2018 4:05 pm

Thanks for the clues. The parent process was the key, I found it in ~/.config/lxsession/LXDE-xo.

User avatar
rados-dataplicity
Posts: 40
Joined: Wed Aug 03, 2016 11:56 am
Location: UK
Contact: Website Facebook Twitter

Re: What is commanding this .py to run?

Wed Feb 21, 2018 10:05 am

Also, the reason it's running as root from rc.local is because rc.local file is executed from systemd service which runs as root
I tinker around with Raspberry Pis daily and make sure that people can easily access theirs remotely.

Community outreach @ dataplicity.com

User avatar
bensimmo
Posts: 4178
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: What is commanding this .py to run?

Wed Feb 21, 2018 12:16 pm

rados-dataplicity wrote:
Wed Feb 21, 2018 10:05 am
Also, the reason it's running as root from rc.local is because rc.local file is executed from systemd service which runs as root
I believe if you use
su pi -c "python3 prog.py" &
it launches as the Pi user.
Correct me if I am wrong though.

Return to “General discussion”