3

I recently got a Raspberry Pi 3 to learn linux and explore the world of single board computers. I am running a recent version of Raspbian (not exactly sure which) on it.

After watching some tutorial videos, I decided to explore stress testing the cpu and observing the reported temperatures. The method I chose was to create two bash files: infinite_loop.bash and cpu_spike.bash.

infinite_loop.bash contains an infinite while loop that does some large exponentiation computation. cpu_spike.bash calls the infinite_loop.bash to run on each of the Pi's 4 cores and this script also displays the Pi's reported temperature every 5 seconds for the duration desired. The scripts work fine (causing all cores to go to 100% and produce an observed temperature increase), but one aspect that does not is trying to kill the infinite_loop.bash process at the end of the cpu_spike.bash script!

ps -A

returns that each process name is listed as 'bash' and not 'infinite_loop.bash' or 'infinite_loop' or anything that is recognizable. So in the example code I followed, I cannot have the following the following line at the end of the cpu_spike script:

killall infinite_loop.bash

The command line returns 'infinite_loop.bash' process not found

so, since I saw that each of the infinite loop process was called 'bash' in the running process list, I am using

killall bash

at the end of the test. Is it bad to do this? Why are my infinite loop processes not being called anything that resembles the name of the script?

Please see my original code for cpu_spike.bash below:

#!/bin/bash
#get initial temp
vcgencmd measure_temp
for i in `seq 4` ; do
    #put infinite loop on each cpu
    /bin/bash /home/pi/infinite_loop.bash &
done

#report temp every 5 seconds for 60 seconds
for value in {1..12}
do
    sleep 5s
    vcgencmd measure_temp
done
killall bash

Note - I am not sure why the formatting for the two for loops is different. The top loop was the one I got from the example I saw online and the second for loop is my own code from another example I saw.

  • you can track the process id of your process using $$. – Raman Sailopal Jan 3 '18 at 16:24
  • 2
    How do you start your scripts? Does the filename show in ps -Af? Does pkill -f infinite_loop.bash not work? – Stéphane Chazelas Jan 3 '18 at 16:25
  • Nor related to the question but to the code : Shouldn't the invocation of infinite_loop.bash also have "$i" as arguments ? – Olivier Dulac Jan 3 '18 at 18:46
  • @StéphaneChazelas yes that worked! ps -Af also showed the process with its filename and the kill command you suggested work too. – PhilosophStein Jan 3 '18 at 19:42
2

Keep in mind that shell scripts are just text files which get interpreted by, well, an interpreter, in your case bash. So any process executing a bash script is basically an instance of bash reading a text file for commands. That's why they all show up as bash in ps.

The solution depends a bit on how you actually start the various infinite_loop.bash scripts. Assuming you do something like

infinite_loop.bash & # cpu 1
infinite_loop.bash & # cpu 2
infinite_loop.bash & # cpu 3
infinite_loop.bash & # cpu 4

you can kill them all at the end by running kill $(jobs -p).

  • the kill command you suggested worked. – PhilosophStein Jan 3 '18 at 19:43
1

You are calling bash and give it as argument the infinite_loop.bash script to interpret. The running process is therefore what you called, ie bash

To have the process named as your infinite_loop.bash, edit your launxhing script by changing :

  /bin/bash /home/pi/infinite_loop.bash

Into :

 /home/pi/infinite_loop.bash

(Ensure that this one has a shebang first line, like your script has, so that it is executed by bash)

Then it will appear with this name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.