2

Before some days I wrote a script and put it somewhere to get it started automatically on booting on my raspberry with wheezy.

ps -ax gives me:

 2041 ?        S      0:00 /usr/sbin/apache2 -k start
 2064 ?        Ss     0:00 /usr/sbin/cron
 2067 ?        S      0:00 /USR/SBIN/CRON
 2068 ?        S      0:00 /USR/SBIN/CRON
 2072 ?        Ss     0:00 /bin/sh -c eibd -t 1023 -S -D -R -T -i --no-tunnel-cl...
 2073 ?        Ss     0:00 /bin/sh -c python2.7 /opt/scripts/nibe_uplink/main.py
 2074 ?        S      0:00 eibd -t 1023 -S -D -R -T -i --no-tunnel-client-queuin...
 2075 ?        Rl     1:25 python2.7 /opt/scripts/nibe_uplink/main.py

pid 2074 is started from /etc/crontab. pid 2075 is started from crontab -e

How can I find where pid 2073 is started from?

  • 2
    What do you mean by "located" and "where is it started"? Do you want to find out the working directory of your script? Please be more precise. – Panki Oct 04 '18 at 08:43

2 Answers2

4

What started this process?

You can use ps to find the parent of each process, either by adding -l (ps -axl) to give "long" output, or by specifically requesting the ppid:

ps -o ppid 2074
 PPID
2072

Repeat for 2072 to see what started that (probably CRON).

Why two processes?

cron passes each command to a shell. From crontab(5):

The entire command portion of the line, up to a newline or a "%" character, will be executed by /bin/sh or by the shell specified in the SHELL variable of the cronfile.

If you have the following line in crontab:

0 * * * * python2.7 /opt/some/script.py

...then when the entry needs to run (every hour, on the hour), cron executes the shell (/bin/sh) with the two arguments -c and python2.7 /opt/some/script.py.

The shell then interprets everything the item after '-c' as a command to run. It finds python2.7 from PATH, and executes it with the single argument /opt/some/script.py. So, depending on your shell (including what /bin/sh points to), there may now be two processes running:

  • /bin/sh -c python2.7 /opt/some/script.py
  • /usr/bin/python2.7 /opt/some/script.py

That's why ps is showing you 2 eibd processes, and 2 python2.7 ones, despite there being only one entry for each in your crontab.

Some shells may avoid forking a second process like this. See Why is there no apparent clone or fork in simple bash command and how it's done?

JigglyNaga
  • 7,886
  • The icing on this particular cake can be found at https://unix.stackexchange.com/questions/466496/ . So this is definitely not the Bourne Again shell, and is most likely the default /bin/sh, the Debian Almquist shell. – JdeBP Oct 04 '18 at 10:45
  • Thank you very much for clarification. I thought there were two separate processes. The hint with PPID was very helpful. The chain for eibd is e.g.: 2074 -> 2072 -> 2067 -> 2064 -> 1 (init) -> 0 – Tobias M. Oct 04 '18 at 10:53
  • @JdeBP Good find, thankyou; edited to include a note about that. – JigglyNaga Oct 04 '18 at 11:12
0

Reading this link tells me that there are multiple ways to run scripts on boot for the raspberry pi. In summation they are:

  1. rc.local
  2. .bashrc
  3. init.d directory
  4. SYSTEMD
  5. crontab

Seeing as you've already checked cron try looking at 1-4.

Beans
  • 121
  • 4