plasticus
Posts: 34
Joined: Tue Nov 01, 2016 10:31 pm

start script via bash = huge CPU drain

Mon Nov 07, 2016 1:43 pm

Hi, I wrote a simple bash script to autostart a couple of programs (pure data and a python script) when the rasp boots up. However I noticed that there's a huge difference in cpu consume and I have no idea why (note that this happens both if I set the bash script to autorun at startup or if I run it manually).

Basically, if I run pure data and the python script manually I can see (via 'top' command in terminal) values in these range, under %CPU:

- python 17 - 19
- puredata 5 - 7

If I run pure data and the python script via the bash script (automatically), the values are:

- python 100 - 110
- puredata 45 - 55

The temperature change as well: around 87 (automatically) and around 75 (manually)
The CPU monitor in the menu bar shows 70-75% (automatically) and 35% (manually)

How is this possible? Any solution? :?

My bash script is:

Code: Select all

#!/bin/bash
#echo "doing autorun script"
sudo puredata /home/pi/puredata/Min/audio.pd & python /home/pi/python/wave/test1.py &

User avatar
CarlRJ
Posts: 598
Joined: Thu Feb 20, 2014 4:00 am
Location: San Diego, California

Re: start script via bash = huge CPU drain

Mon Nov 07, 2016 8:38 pm

I'm not sure why you're seeing the difference in CPU usage. One possibility is that they're running at different "nice" values between the two scenarios (compare the values in the "NI" column in top), though that wouldn't likely cause the system to spin up so hard. A more likely possibility is that in the higher usage scenario, they are disconnected from some resource they expect to be there, and are sitting in a tight loop trying to access it.

Aside from that, though, listing both commands on one line hides the way they're actually running - the first '&' ends the first command (sudo puredata ...), which is followed by an entirely unrelated second command (python ...) which runs without the benefit of root permission (unless you're root when you run it).

The sudo command will stay around as the parent of the puredata command until the puredata command exits. If you want both commands to run as root, and you don't want sudo hanging around, you'd need something like this:

Code: Select all

$ cat another_file
puredata /home/pi/puredata/Min/audio.pd &
python /home/pi/python/wave/test1.py &
$
$ sudo sh another_file
$
This way, sudo will run sh with root permissions, sh will run a script which will exit quickly (since all it does is start two processes without waiting for them to finish), and then sudo will go away. Your two processes (puredata and python), however, will remain running in the background, with root permissions.

plasticus
Posts: 34
Joined: Tue Nov 01, 2016 10:31 pm

Re: start script via bash = huge CPU drain

Mon Nov 07, 2016 9:00 pm

Hi,

thanks for the reply. Not sure I understand when you say
they are disconnected from some resource they expect to be there, and are sitting in a tight loop trying to access it
but in fact, the python script is connecting to a usb device but it normally can do that in a couple of seconds and then carry on with the script so I don't think it's related to that.
Also, I didn't mention before, the bash script is called in /etc/profile with sudo /path_to_bash_script.
What else could I do to see what's going on?

Does changing my bash script like this work the same as doing what you suggested?

Code: Select all

sudo puredata /home/pi/puredata/Min/audio.pd &
sudo python /home/pi/python/wave/test1.py

User avatar
CarlRJ
Posts: 598
Joined: Thu Feb 20, 2014 4:00 am
Location: San Diego, California

Re: start script via bash = huge CPU drain

Mon Nov 07, 2016 10:38 pm

plasticus wrote:
Not sure I understand when you say "they are disconnected from some resource they expect to be there, and are sitting in a tight loop trying to access it" ...

Also, I didn't mention before, the bash script is called in /etc/profile with sudo /path_to_bash_script.
What else could I do to see what's going on?

Does changing my bash script like this work the same as doing what you suggested?
For the processes to be eating up more cpu time, they are either doing more useful work, or more unnecessary work - the latter is often a case where a program is stuck in a loop trying the same thing over and over again, with it failing each time. Often times this is trying to access a resource they can't when running in the current situation. The trick, of course, is figuring out what is different between the two.

Changing the script as you show would, indeed, run both commands via sudo. Running from /etc/profile is a terrible idea, though - this gets read for every login shell, so if you log in multiple times, it'll run multiple times. If you want to run these commands once, at startup, as root, add them to the end of /etc/rc.local (that's what it's there for - per-machine customizations), and get rid of the "sudo", since they'll be running as root (yes, there are even better solutions involving systemd, but that's more configuration, while this approach is moving the lines from one startup file in /etc to another).

I would suggest looking at the output of "sudo ps auxf" to compare how your processes are running under the two different startup scenarios. Is the parent process the same in both cases? Any of the other columns significantly different?

Also, get the output of "printenv" (or bash's built-in "env") from each of the two scenarios, and compare them to see if one has, say, a different path than the other. This can be as simple as adding a line "env > /tmp/env$$" to your script, and then running it in both scenarios and comparing the two files.

vman81
Posts: 31
Joined: Wed Nov 02, 2011 11:13 am

Re: start script via bash = huge CPU drain

Mon Nov 07, 2016 10:57 pm

What happens if you disable dash and reboot?

Sudo dpkg-reconfigure dash

plasticus
Posts: 34
Joined: Tue Nov 01, 2016 10:31 pm

Re: start script via bash = huge CPU drain

Tue Nov 08, 2016 12:35 am

vman81 wrote:What happens if you disable dash and reboot?
Sudo dpkg-reconfigure dash
Hi, considering that I completely new to linux and I don't want to mess up everything, before I try the command could you also tell me how to re-enable dash? So that I can set it back in case that disabling it doesn't change anything. thanks :D
CarlRJ wrote: Running from /etc/profile is a terrible idea, though - this gets read for every login shell, so if you log in multiple times, it'll run multiple times. If you want to run these commands once, at startup, as root, add them to the end of /etc/rc.local (that's what it's there for - per-machine customizations), and get rid of the "sudo", since they'll be running as root (yes, there are even better solutions involving systemd, but that's more configuration, while this approach is moving the lines from one startup file in /etc to another).
I tried both via systemd (this tutorial) and rc.local (this tutorial) without success. The only way I managed to have the programs to autorun at startup was to do as I did :(
CarlRJ wrote: I would suggest looking at the output of "sudo ps auxf" to compare how your processes are running under the two different startup scenarios. Is the parent process the same in both cases? Any of the other columns significantly different?
OK! they are different! The first is the one I run manually and the second one is the automatic run. It looks like in the second one the scripts are being executed many times (sometimes sudo sometimes not) !! What can it be?

manual

Code: Select all

pi         832  0.0  0.6  59100  6336 ?        Sl   00:18   0:00 /usr/lib/gvfs/gvfsd-trash --spawner :1.1 /org/gtk/gvfs/exec_spaw/0
pi         838  0.0  0.5  28292  4836 ?        Ssl  00:18   0:00 /usr/lib/menu-cache/menu-cached /tmp/.menu-cached-:0-pi
root       928  0.0  0.0      0     0 ?        S    00:18   0:00 [jbd2/mmcblk0p5-]
root       929  0.0  0.0      0     0 ?        S<   00:18   0:00 [ext4-rsv-conver]
root       937  0.0  0.0      0     0 ?        S    00:18   0:00 [kworker/u8:3]
pi         954  2.0  1.4  28060 13812 ?        Sl   00:19   0:03 wish /usr/lib/puredata/tcl/pd-gui.tcl --
pi         956  3.0  0.4  23204  4168 ?        Sl   00:19   0:04 /usr/lib/puredata/tcl/../bin/pd -guiport 49507
pi         958  0.0  0.0   1912   400 ?        S    00:19   0:00 sh -c /usr/lib/puredata/tcl/../bin/pd-watchdog
pi         959  0.0  0.0   1840   424 ?        S    00:19   0:00 /usr/lib/puredata/tcl/../bin/pd-watchdog
pi         991  7.3  2.6  40812 25164 ?        Rl   00:19   0:09 /usr/bin/python /usr/bin/idle /home/pi/python/Mindwave/test1.py
pi        1025 22.1  2.1  62376 20620 ?        Sl   00:21   0:03 /usr/bin/python -c __import__('idlelib.run').run.main(True) 42007
pi        1031  4.1  1.8  45112 17624 ?        Rl   00:21   0:00 lxterminal
pi        1032  0.3  0.1   2348  1460 ?        S    00:21   0:00 gnome-pty-helper
pi        1033  2.6  0.4   6224  4144 pts/0    Ss   00:21   0:00 /bin/bash
pi        1044  0.0  0.2   4740  2168 pts/0    R+   00:21   0:00 ps aux

autorun

Code: Select all

pi         650  0.2  1.1  50744 11272 ?        Ssl  00:32   0:00 /usr/bin/lxsession -s LXDE-pi -e LXDE
root       680  0.0  0.3   6780  3140 ?        S    00:32   0:00 sudo puredata /home/pi/puredata/MindTheChair/audio.pd
root       681  0.0  0.3   6780  3108 ?        S    00:32   0:00 sudo python /home/pi/python/Mindwave/test1.py
root       698 44.4  0.4  23204  4296 ?        Sl   00:32   0:31 puredata /home/pi/puredata/MindTheChair/audio.pd
root       703  0.6  1.6  35388 15888 ?        S    00:32   0:00 python /home/pi/python/Mindwave/test1.py
pi         704  0.0  0.0   3700   220 ?        Ss   00:32   0:00 /usr/bin/ssh-agent /usr/bin/dbus-launch --exit-with-session x-session-manager
pi         707  0.0  0.1   3692  1592 ?        S    00:32   0:00 /usr/bin/dbus-launch --exit-with-session x-session-manager
root       708  0.0  0.0   1912   360 ?        S    00:32   0:00 sh -c TCL_LIBRARY="/usr/lib/puredata/lib/tcl/library" TK_LIBRARY="/usr/lib/puredata/lib/tk/l
root       709  0.0  0.0   1912   380 ?        S    00:32   0:00 sh -c /usr/lib/puredata/bin/pd-watchdog
root       710  0.0  0.0   1840   388 ?        S    00:32   0:00 /usr/lib/puredata/bin/pd-watchdog
pi         711  0.1  0.2   5600  2220 ?        Ss   00:32   0:00 /usr/bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
root       712 82.5  5.3  66056 51112 ?        Rl   00:32   0:58 wish /usr/lib/puredata/tcl//pd-gui.tcl 5400
pi         719  0.0  0.5  30988  5600 ?        Sl   00:32   0:00 /usr/lib/gvfs/gvfsd
root       724  0.0  0.0      0     0 ?        S<   00:32   0:00 [kworker/u9:0]
root       725  0.0  0.0      0     0 ?        S<   00:32   0:00 [hci0]
root       726  0.0  0.0      0     0 ?        S<   00:32   0:00 [hci0]
root       727  0.0  0.0      0     0 ?        S<   00:32   0:00 [kworker/u9:1]
root       728  0.0  0.0   2068   132 ?        S    00:32   0:00 /usr/bin/hciattach /dev/serial1 bcm43xx 921600 noflow -
root       729  0.0  0.0      0     0 ?        S<   00:32   0:00 [kworker/u9:2]
pi         736  0.0  0.4  47252  4356 ?        Sl   00:32   0:00 /usr/lib/gvfs/gvfsd-fuse /run/user/1000/gvfs -f -o big_writes
root       740  0.0  0.3   5008  3356 ?        Ss   00:32   0:00 /usr/lib/bluetooth/bluetoothd
root       755  1.0  0.0      0     0 ?        S<   00:32   0:00 [kworker/2:1H]
root       758  0.0  0.0      0     0 ?        S    00:32   0:00 [kworker/u8:3]
pi         761  0.3  0.4   6384  4252 tty1     S+   00:32   0:00 -bash
root       775  0.0  0.3   6780  3184 tty1     S+   00:32   0:00 sudo puredata /home/pi/puredata/MindTheChair/audio.pd
root       776  0.0  0.3   6780  3168 tty1     S+   00:32   0:00 sudo python /home/pi/python/Mindwave/test1.py
root       779  0.0  0.0      0     0 ?        S<   00:32   0:00 [kworker/3:1H]
root       794  0.0  0.4   6300  3980 tty1     S+   00:32   0:00 puredata /home/pi/puredata/MindTheChair/audio.pd
root       797 96.4  1.6  35356 15896 tty1     Rl+  00:32   1:06 python /home/pi/python/Mindwave/test1.py
root       799  0.0  0.0      0     0 tty1     Z+   00:32   0:00 [sh] <defunct>
root       800  0.0  0.0      0     0 tty1     Z+   00:32   0:00 [sh] <defunct>
root       801  0.0  0.0   1840   376 tty1     S+   00:32   0:00 /usr/lib/puredata/bin/pd-watchdog
pi         812  0.7  1.3  21388 12444 ?        S    00:32   0:00 openbox --config-file /home/pi/.config/openbox/lxde-pi-rc.xml

User avatar
CarlRJ
Posts: 598
Joined: Thu Feb 20, 2014 4:00 am
Location: San Diego, California

Re: start script via bash = huge CPU drain

Tue Nov 08, 2016 4:36 am

Unfortunately, you've run "ps aux", rather than "ps auxf". The "f" is important, as it causes ps to show the parent/child relationship of processes as a tree structure ("f" for "forest", since "t" was already used). The "f" would have made the output more useful; without it, there's considerable guesswork here. But it does look like you've got one copy of a set of related processes running in the manual example, and two copies in the autorun example - with one set connected to tty1, and the other set not connected to a tty. I'd venture a guess that one set started at boot time, and the second set started when you opened up a terminal window inside X Windows - because you've got it wired to run from /etc/profile, which is potentially getting run multiple times.

Which also points out... it appears the thing you're trying to run uses X Windows; this explains why the systemd and /etc/rc.local approaches did not work - you don't really want something to start at system startup time, you want something to start after X Windows is running (starting X Windows is not part of the system startup process per se, it's more like an optional user program that can be run shortly after system startup - I don't have it running on any of my Raspberry Pi's). There are ways to have something run automatically after X Windows starts, but they're specific not just to X Windows, but to which particular window manager you're using for X Windows. I believe LXDE is the default on Raspbian, so this article would likely help: How To Autostart Apps In Rasbian LXDE Desktop. I can't be much more help for getting things to work right in X Windows, as my experience with that is long in the past, on different window managers than Raspbian uses.

vman81
Posts: 31
Joined: Wed Nov 02, 2011 11:13 am

Re: start script via bash = huge CPU drain

Tue Nov 08, 2016 12:44 pm

plasticus wrote:Hi, considering that I completely new to linux and I don't want to mess up everything, before I try the command could you also tell me how to re-enable dash? So that I can set it back in case that disabling it doesn't change anything. thanks :D
Just run it again to re-enable :)

plasticus
Posts: 34
Joined: Tue Nov 01, 2016 10:31 pm

Re: start script via bash = huge CPU drain

Tue Nov 08, 2016 7:03 pm

Hi, sorry I see I missed the 'f': so this is the output with 'ps auxf' command

manual

Code: Select all

pi         639  0.0  0.1   6848  1252 ?        S    18:51   0:00  \_ (sd-pam)  
root       669  0.0  0.0   2068   132 ?        S    18:51   0:00 /usr/bin/hciattach /dev/serial1 bcm43xx 921600 noflow -
root       682  0.0  0.3   5008  3484 ?        Ss   18:51   0:00 /usr/lib/bluetooth/bluetoothd
pi         708  0.0  0.1   3692  1592 ?        S    18:51   0:00 /usr/bin/dbus-launch --exit-with-session x-session-manager
pi         709  0.0  0.2   5600  2160 ?        Ss   18:51   0:00 /usr/bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
pi         744  0.0  0.5  30988  5488 ?        Sl   18:51   0:00 /usr/lib/gvfs/gvfsd
pi         751  0.0  0.4  47252  4348 ?        Sl   18:51   0:00 /usr/lib/gvfs/gvfsd-fuse /run/user/1000/gvfs -f -o big_writes
pi         773  0.0  0.0   3700   220 ?        Ss   18:51   0:00 /usr/bin/ssh-agent -s
root       774  0.0  0.6  36700  6088 ?        Ssl  18:51   0:00 /usr/lib/policykit-1/polkitd --no-debug
pi         787  0.0  0.8  60284  8008 ?        Sl   18:51   0:00 /usr/lib/gvfs/gvfs-udisks2-volume-monitor
root       791  0.0  0.6  54580  6492 ?        Ssl  18:51   0:00 /usr/lib/udisks2/udisksd --no-debug
pi         803  0.0  0.5  29932  5212 ?        Sl   18:51   0:00 /usr/lib/gvfs/gvfs-mtp-volume-monitor
pi         807  0.0  0.6  42416  6336 ?        Sl   18:51   0:00 /usr/lib/gvfs/gvfs-afc-volume-monitor
pi         813  0.0  0.5  30952  5504 ?        Sl   18:51   0:00 /usr/lib/gvfs/gvfs-gphoto2-volume-monitor
pi         817  0.0  0.5  30036  5368 ?        Sl   18:51   0:00 /usr/lib/gvfs/gvfs-goa-volume-monitor
pi         824  0.0  0.6  59100  6288 ?        Sl   18:51   0:00 /usr/lib/gvfs/gvfsd-trash --spawner :1.1 /org/gtk/gvfs/exec_spaw/0
pi         830  0.0  0.5  28292  4772 ?        Ssl  18:51   0:00 /usr/lib/menu-cache/menu-cached /tmp/.menu-cached-:0-pi
pi         933  3.1 10.9 294424 103872 ?       Sl   18:52   0:09 epiphany-browser
pi         965  0.0  0.5  20740  5320 ?        Sl   18:52   0:00 /usr/lib/gvfs/gvfsd-metadata
pi         989  0.6  1.8  45116 17956 ?        Rl   18:52   0:01 lxterminal
pi         990  0.0  0.1   2348  1464 ?        S    18:52   0:00  \_ gnome-pty-helper
pi         991  0.1  0.4   6252  4288 pts/0    Ss   18:52   0:00  \_ /bin/bash
pi        1098  0.0  0.2   4896  2204 pts/0    R+   18:56   0:00      \_ ps auxf
pi        1036  5.1  1.4  28480 14164 ?        Sl   18:54   0:06 wish /usr/lib/puredata/tcl/pd-gui.tcl --
pi        1038  3.5  0.4  23204  4360 ?        Sl   18:54   0:04  \_ /usr/lib/puredata/tcl/../bin/pd -guiport 53092
pi        1040  0.0  0.0   1912   364 ?        S    18:54   0:00      \_ sh -c /usr/lib/puredata/tcl/../bin/pd-watchdog
pi        1041  0.0  0.0   1840   408 ?        S    18:54   0:00          \_ /usr/lib/puredata/tcl/../bin/pd-watchdog
pi        1079 45.7  2.8  42820 27100 ?        Rl   18:56   0:21 /usr/bin/python /usr/bin/idle /home/pi/python/Mindwave/test1.py
pi        1092 23.1  2.1  62376 20388 ?        Sl   18:56   0:09  \_ /usr/bin/python -c __import__('idlelib.run').run.main(True) 51478
autorun

Code: Select all

pi         816  0.2  1.8  77444 17484 ?        Sl   19:00   0:00          \_ pcmanfm --desktop --profile LXDE-pi
ntp        549  0.0  0.3   5688  3736 ?        Ss   19:00   0:00 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 106:111
root       554  0.0  0.2   5668  2796 tty1     Ss   19:00   0:00 /bin/login -f   
pi         761  0.1  0.4   6392  4248 tty1     S+   19:00   0:00  \_ -bash
root       557  0.0  0.2   3872  1980 ttyS0    Ss+  19:00   0:00 /sbin/agetty --keep-baud 115200 38400 9600 ttyS0 vt102
pi         640  0.0  0.3   4976  3288 ?        Ss   19:00   0:00 /lib/systemd/systemd --user
pi         645  0.0  0.1   6796  1292 ?        S    19:00   0:00  \_ (sd-pam)  
root       679  0.0  0.3   6780  3092 ?        S    19:00   0:00 sudo puredata /home/pi/puredata/MindTheChair/audio.pd
root       697 47.0  0.4  23204  4184 ?        Sl   19:00   1:02  \_ puredata /home/pi/puredata/MindTheChair/audio.pd
root       707  0.0  0.0   1912   364 ?        S    19:00   0:00      \_ sh -c TCL_LIBRARY="/usr/lib/puredata/lib/tcl/library" TK_LIBRARY="/usr/lib/puredata/
root       711 85.3  9.4 105844 89956 ?        Rl   19:00   1:53      |   \_ wish /usr/lib/puredata/tcl//pd-gui.tcl 5400
root       708  0.0  0.0   1912   380 ?        S    19:00   0:00      \_ sh -c /usr/lib/puredata/bin/pd-watchdog
root       709  0.0  0.0   1840   396 ?        S    19:00   0:00          \_ /usr/lib/puredata/bin/pd-watchdog
root       680  0.0  0.3   6780  3168 ?        S    19:00   0:00 sudo python /home/pi/python/Mindwave/test1.py
root       702  0.3  1.6  35388 15856 ?        S    19:00   0:00  \_ python /home/pi/python/Mindwave/test1.py
pi         706  0.0  0.1   3692  1620 ?        S    19:00   0:00 /usr/bin/dbus-launch --exit-with-session x-session-manager
pi         710  0.1  0.2   5600  2316 ?        Ss   19:00   0:00 /usr/bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
pi         718  0.0  0.5  30988  5676 ?        Sl   19:00   0:00 /usr/lib/gvfs/gvfsd
pi         725  0.0  0.4  47252  4244 ?        Sl   19:00   0:00 /usr/lib/gvfs/gvfsd-fuse /run/user/1000/gvfs -f -o big_writes
root       731  0.0  0.0   2068   132 ?        S    19:00   0:00 /usr/bin/hciattach /dev/serial1 bcm43xx 921600 noflow -
root       741  0.0  0.3   5008  3432 ?        Ss   19:00   0:00 /usr/lib/bluetooth/bluetoothd
root       774  0.0  0.3   6780  3236 tty1     S+   19:00   0:00 sudo puredata /home/pi/puredata/MindTheChair/audio.pd
root       795  0.0  0.4   6300  3856 tty1     S+   19:00   0:00  \_ puredata /home/pi/puredata/MindTheChair/audio.pd
root       796  0.0  0.0      0     0 tty1     Z+   19:00   0:00      \_ [sh] <defunct>
root       797  0.0  0.0      0     0 tty1     Z+   19:00   0:00      \_ [sh] <defunct>
root       775  0.0  0.3   6780  3108 tty1     S+   19:00   0:00 sudo python /home/pi/python/Mindwave/test1.py
root       792 96.5  1.6  35356 15884 tty1     Rl+  19:00   2:06  \_ python /home/pi/python/Mindwave/test1.py
root       798  0.0  0.0   1840   392 tty1     S+   19:00   0:00 /usr/lib/puredata/bin/pd-watchdog
pi         822  0.0  0.0   3700   220 ?        Ss   19:00   0:00 /usr/bin/ssh-agent -s
root       823  0.0  0.6  36700  6088 ?        Ssl  19:00   0:00 /usr/lib/policykit-1/polkitd --no-debug
pi         836  0.1  0.8  60284  7916 ?        Sl   19:00   0:00 /usr/lib/gvfs/gvfs-udisks2-volume-monitor
root       841  0.1  0.6  54584  6532 ?        Ssl  19:00   0:00 /usr/lib/udisks2/udisksd --no-debug
pi         934  0.0  0.5  29932  5204 ?        Sl   19:00   0:00 /usr/lib/gvfs/gvfs-mtp-volume-monitor
pi         940  0.0  0.6  42416  6496 ?        Sl   19:00   0:00 /usr/lib/gvfs/gvfs-afc-volume-monitor
pi         946  0.0  0.5  30952  5436 ?        Sl   19:00   0:00 /usr/lib/gvfs/gvfs-gphoto2-volume-monitor
pi         950  0.0  0.4  30036  4728 ?        Sl   19:00   0:00 /usr/lib/gvfs/gvfs-goa-volume-monitor
pi         957  0.0  0.6  49884  6292 ?        Sl   19:00   0:00 /usr/lib/gvfs/gvfsd-trash --spawner :1.1 /org/gtk/gvfs/exec_spaw/0
pi         961  0.0  0.5  28292  4836 ?        Ssl  19:00   0:00 /usr/lib/menu-cache/menu-cached /tmp/.menu-cached-:0-pi
pi        1159  0.3  1.8  44988 17228 ?        Sl   19:01   0:00 lxterminal
pi        1171  0.0  0.1   2348  1460 ?        S    19:01   0:00  \_ gnome-pty-helper
pi        1172  0.1  0.4   6240  4264 pts/0    Ss   19:01   0:00  \_ /bin/bash
pi        1766  0.0  0.2   4896  2248 pts/0    R+   19:02   0:00      \_ ps auxf
pi        1447 44.5 10.9 295448 103508 ?       Sl   19:01   0:23 epiphany-browser
pi        1453  0.0  0.4  20648  3928 ?        Sl   19:01   0:00 /usr/lib/gvfs/gvfsd-metadata


User avatar
CarlRJ
Posts: 598
Joined: Thu Feb 20, 2014 4:00 am
Location: San Diego, California

Re: start script via bash = huge CPU drain

Sun Nov 13, 2016 5:45 am

plasticus wrote:up!
If you're looking for additional help... did you read the second paragraph of my last reply? You're getting multiple instances because you're using /etc/profile. That's the wrong place to start programs, unless you want an additional instance for every login shell started. And everything I said in that reply still holds. The "ps auxf" output makes more somewhat clear what is happening, but it still basically boils down to starting it from the wrong place.

The very first thing on the page you linked to as "rc.local (this tutorial)", earlier, says:
Auto running applications in the GUI
See here
And that link leads to a page talking about starting GUI apps from /home/pi/.config/lxsession/LXDE-pi/autostart. Have you tried that?

The ps output shows the processes for "Mindwave" runing once, when started manually, while when using /etc/profile, you're getting two sets of "Mindwave" and also two sets of another puredata app(?) called "MindTheChair". I have no idea what that additional application is or how you got it started. Each one of the puredata processes is running under its own sudo process. As I said earlier, if you put the commands into a script (containing, e.g., "foo &" and "bar &") and then run that script with sudo scriptname, each process will get root permission without having a bunch of sudo processes hanging around.

Actually, I note that for all the work you're going through to start the automatically-started versions with "sudo"... the manually started copy of puredata and Mindwave is running as user pi. So why go to all the extra work? You don't need "sudo" at all, and getting that out of the picture would get rid of still more unneeded processes.

So when you run it manually, you've got a puredata gui and a puredata watchdog process, and then one copy of your Mindwave puredata app running under IDLE.

When you run it from /etc/profile, you're getting the puredata gui and watchdog, which is running under one copy of MindTheChair (whatever that is), and one copy of your Mindwave app, plus, because of one of your login shells (not clear which or the order things happened in), you've got a second copy of the watchdog, a second copy of MindTheChair, a second copy of Mindwave, plus both copies of Mindwave and both copies of MindTheChair are each running under separate, unnecessary, sudo processes. You have fifteen processes running when you only need five, and it's possible some of the many puredata processes are fighting over access to shared resources. Move it from /etc/profile to LXDE's autostart, and drop the unnecessary "sudo" commands, and you'll shed two-thirds of the processes.

(Also, the copy you're running manually, you're starting from inside IDLE. This is not necessary - if the script starts with the proper "#!" line, you can run it directly.)

plasticus
Posts: 34
Joined: Tue Nov 01, 2016 10:31 pm

Re: start script via bash = huge CPU drain

Sun Nov 13, 2016 2:02 pm

Hi,

sorry I didn't understand your previous response was still valid for the "ps auxf" command. Ok thank you..I'm trying to decifrate your suggestions.
CarlRJ wrote: The very first thing on the page you linked to as "rc.local (this tutorial)", earlier, says:
Auto running applications in the GUI
See here
And that link leads to a page talking about starting GUI apps from /home/pi/.config/lxsession/LXDE-pi/autostart. Have you tried that?
I didn't try this before as I don't actually need the GUI (but I guess I'm confused about what this means). However, following this tutorial, I don't have the file

Code: Select all

 /root/.config/lxsession/LXDE-pi/autostart
and I need root permissions as the python script will use GPIO.
I do have

Code: Select all

/home/pi/.config/lxsession/LXDE-pi/autostart
but the tutorial says that this is not for the root user (running the GUI with "sudo startx")
CarlRJ wrote: The ps output shows the processes for "Mindwave" runing once, when started manually, while when using /etc/profile, you're getting two sets of "Mindwave" and also two sets of another puredata app(?) called "MindTheChair". I have no idea what that additional application is or how you got it started.
it's included in my startup script. it's another software that I need to run on startup
CarlRJ wrote: Each one of the puredata processes is running under its own sudo process. As I said earlier, if you put the commands into a script (containing, e.g., "foo &" and "bar &") and then run that script with sudo scriptname, each process will get root permission without having a bunch of sudo processes hanging around.
ok, my script is

Code: Select all

sudo puredata /home/pi/puredata/MindTheChair/audio.pd &
sudo python /home/pi/python/Mindwave/test1.py
CarlRJ wrote: Actually, I note that for all the work you're going through to start the automatically-started versions with "sudo"... the manually started copy of puredata and Mindwave is running as user pi. So why go to all the extra work? You don't need "sudo" at all, and getting that out of the picture would get rid of still more unneeded processes.
ok so I can change the script like this, right?

Code: Select all

puredata /home/pi/puredata/MindTheChair/audio.pd &
python /home/pi/python/Mindwave/test1.py
CarlRJ wrote: So when you run it manually, you've got a puredata gui and a puredata watchdog process, and then one copy of your Mindwave puredata app running under IDLE.

When you run it from /etc/profile, you're getting the puredata gui and watchdog, which is running under one copy of MindTheChair (whatever that is), and one copy of your Mindwave app, plus, because of one of your login shells (not clear which or the order things happened in), you've got a second copy of the watchdog, a second copy of MindTheChair, a second copy of Mindwave, plus both copies of Mindwave and both copies of MindTheChair are each running under separate, unnecessary, sudo processes. You have fifteen processes running when you only need five, and it's possible some of the many puredata processes are fighting over access to shared resources. Move it from /etc/profile to LXDE's autostart, and drop the unnecessary "sudo" commands, and you'll shed two-thirds of the processes.
ok, as before, I don't have this file

Code: Select all

/root/.config/lxsession/LXDE-pi/autostart
:(
CarlRJ wrote: (Also, the copy you're running manually, you're starting from inside IDLE. This is not necessary - if the script starts with the proper "#!" line, you can run it directly.)
ok, done.

Thank you A LOT!! :D

User avatar
CarlRJ
Posts: 598
Joined: Thu Feb 20, 2014 4:00 am
Location: San Diego, California

Re: start script via bash = huge CPU drain

Sun Nov 13, 2016 9:38 pm

plasticus wrote:I didn't try this before as I don't actually need the GUI (but I guess I'm confused about what this means). However, following this tutorial, I don't have the file /root/.config/lxsession/LXDE-pi/autostart and I need root permissions as the python script will use GPIO. I do have /home/pi/.config/lxsession/LXDE-pi/autostart but the tutorial says that this is not for the root user (running the GUI with "sudo startx")
It appears you do not need root permissions to use GPIO, as your manually-run scenario shows no associated processes running as root (unless the MindTheChair process needs root, and was running, and wasn't in the ps output you provided - also, I think the need for root permission to access GPIO pins was removed in the last year or so). By GUI, I mean X11 / X-Windows. PureData is going out of its way to use wish, the "Simple windowing shell" for Tcl/Tk (Tk being a graphical toolkit on top of Tcl); I am presuming this is necessary to how it functions. Thus, your script, by virtue of being implemented in PureData, requires X11, whether you want to display anything or not.

So, you don't want to modify root's X11 startup, you want to modify user pi's startup, and /home/pi/.config/lxsession/LXDE-pi/autostart is where you want to do that (if the file didn't exist, you could create it, and LXDE will read it on startup).
plasticus wrote:it's included in my startup script. it's another software that I need to run on startup
Ah, okay. FWIW, MindTheChair doesn't appear to be running in your manually-run scenario (unless those lines were outside the bit you posted).
plasticus wrote:ok, my script is

Code: Select all

sudo puredata /home/pi/puredata/MindTheChair/audio.pd &
sudo python /home/pi/python/Mindwave/test1.py
And (to get the processes running without a bunch of sudo processes hanging around), you'd want to remove the "sudo" from the front of each line, and execute that script with sudo scriptname - the script will run with elevated (root) permissions, it will launch two processes into the background, both running as root, and then your startup script ("scriptname", above) will finish and the single sudo process will finish, and those two launched processes (and their descendents) will still be running as root.
plasticus wrote:ok so I can change the script like this, right?

Code: Select all

puredata /home/pi/puredata/MindTheChair/audio.pd &
python /home/pi/python/Mindwave/test1.py
Yes, it would appear so. And in the case of the Mindwave script (at least), if you have "#!/usr/bin/env python" as the first line, and set the execute bit on the script (once) with "chmod a+x /home/pi/python/Mindwave/test1.py", then you don't need to say "python" in front of it, you can run it as a "first class citizen" on the system (that specially crafted first line tells the kernel how to go about executing the script, and the execute bit in the script's permissions tell the kernel that the file is something it can try to execute).

I hope I don't sound too abrupt, in all of this. I apologize if I come across that way. I don't mean to be. Just trying to get a lot of details across in a hurry.

plasticus
Posts: 34
Joined: Tue Nov 01, 2016 10:31 pm

Re: start script via bash = huge CPU drain

Mon Nov 14, 2016 12:22 am

Hi, ok I changed the autostart file and now the processes are autorunning.

This is what it looks like now (added the last 2 lines):

Code: Select all

@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
@xscreensaver -no-splash
@point-rpi
@puredata /home/pi/Desktop/mind/pd/audio.pd
@python /home/pi/Desktop/mind/python/test1.py

This is the "ps auxf" for autostart

Code: Select all

root         1  1.6  0.4  22968  4016 ?        Ss   00:03   0:03 /sbin/init splash
root       132  0.1  0.3  11904  3128 ?        Ss   00:03   0:00 /lib/systemd/systemd-udevd
root       136  0.2  0.2   9944  2808 ?        Ss   00:03   0:00 /lib/systemd/systemd-journald
root       452  0.0  0.2   5072  2348 ?        Ss   00:03   0:00 /usr/sbin/cron -f
root       454  0.0  0.2   3852  2424 ?        Ss   00:03   0:00 /lib/systemd/systemd-logind
avahi      461  0.0  0.2   3876  2544 ?        Ss   00:03   0:00 avahi-daemon: running [raspberrypi.local]
avahi      468  0.0  0.0   3876   240 ?        S    00:03   0:00  \_ avahi-daemon: chroot helper
message+   462  0.1  0.3   5712  3168 ?        Ss   00:03   0:00 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation
root       466  0.0  0.1   2564  1776 ?        Ss   00:03   0:00 /sbin/dhcpcd -q -b
root       517  0.0  0.3  32144  2876 ?        Ssl  00:03   0:00 /usr/sbin/rsyslogd -n
root       520  0.0  0.3   7156  3380 ?        Ss   00:03   0:00 /sbin/wpa_supplicant -s -B -P /run/wpa_supplicant.wlan0.pid -i wlan0 -D nl80211,wext -c /etc/
root       540  0.0  0.4   7864  4328 ?        Ss   00:03   0:00 /usr/sbin/sshd -D
root       571  0.0  0.7  40520  6932 ?        Ssl  00:03   0:00 /usr/sbin/lightdm
root       663  7.1  7.3 224168 69328 tty7     Ssl+ 00:03   0:12  \_ /usr/bin/X :0 -seat seat0 -auth /var/run/lightdm/root/:0 -nolisten tcp vt7 -novtswitch
root       675  0.0  0.7  32880  7368 ?        Sl   00:03   0:00  \_ lightdm --session-child 13 16
pi         689  0.1  1.2  52244 12232 ?        Ssl  00:03   0:00      \_ /usr/bin/lxsession -s LXDE-pi -e LXDE
pi         719  0.0  0.0   3700   220 ?        Ss   00:03   0:00          \_ /usr/bin/ssh-agent /usr/bin/dbus-launch --exit-with-session x-session-manager
pi         744  1.4  1.2  21060 12116 ?        S    00:03   0:02          \_ openbox --config-file /home/pi/.config/openbox/lxde-pi-rc.xml
pi         747  0.0  0.9  30372  8648 ?        Sl   00:03   0:00          \_ lxpolkit
pi         749  2.2  2.8  96636 26872 ?        Sl   00:03   0:03          \_ lxpanel --profile LXDE-pi
pi         750  1.5  2.7 150932 26268 ?        Sl   00:03   0:02          \_ pcmanfm --desktop --profile LXDE-pi
pi         754 48.8  0.6  29536  6384 ?        Sl   00:03   1:24          \_ puredata /home/pi/Desktop/mind/pd/audio.pd
pi         786  0.0  0.0   1912   396 ?        S    00:03   0:00          |   \_ sh -c TCL_LIBRARY="/usr/lib/puredata/lib/tcl/library" TK_LIBRARY="/usr/lib/pu
pi         787 87.8 12.6 141324 119644 ?       Rl   00:03   2:30          |   |   \_ wish /usr/lib/puredata/tcl//pd-gui.tcl 5400
pi         789  0.0  0.0   1912   388 ?        S    00:03   0:00          |   \_ sh -c /usr/lib/puredata/bin/pd-watchdog
pi         790  0.0  0.0   1840   408 ?        S    00:03   0:00          |       \_ /usr/lib/puredata/bin/pd-watchdog
pi         756 95.2  1.6  35376 15972 ?        Rl   00:03   2:43          \_ python /home/pi/Desktop/mind/python/test1.py
nobody     638  0.1  0.1   2292  1436 ?        Ss   00:03   0:00 /usr/sbin/thd --daemon --triggers /etc/triggerhappy/triggers.d/ --socket /var/run/thd.socket 
root       652  0.0  0.2   5668  2716 tty1     Ss   00:03   0:00 /bin/login -f   
pi         824  0.1  0.4   6532  4480 tty1     S+   00:03   0:00  \_ -bash
ntp        655  0.0  0.3   5688  3684 ?        Ss   00:03   0:00 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 106:111
pi         683  0.0  0.3   4976  3336 ?        Ss   00:03   0:00 /lib/systemd/systemd --user
pi         686  0.0  0.1   6776  1156 ?        S    00:03   0:00  \_ (sd-pam)         
pi         722  0.0  0.1   3692  1664 ?        S    00:03   0:00 /usr/bin/dbus-launch --exit-with-session x-session-manager
pi         723  0.0  0.2   5608  2124 ?        Ss   00:03   0:00 /usr/bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
pi         729  0.0  0.5  30988  5668 ?        Sl   00:03   0:00 /usr/lib/gvfs/gvfsd
pi         733  0.0  0.5  48524  5212 ?        Sl   00:03   0:00 /usr/lib/gvfs/gvfsd-fuse /run/user/1000/gvfs -f -o big_writes
root       755  0.0  0.7  40956  7276 ?        Ssl  00:03   0:00 /usr/lib/policykit-1/polkitd --no-debug
pi         761  0.0  0.0   3700   220 ?        Ss   00:03   0:00 /usr/bin/ssh-agent -s
root       766  0.0  0.0   2068   148 ?        S    00:03   0:00 /usr/bin/hciattach /dev/serial1 bcm43xx 921600 noflow -
root       780  0.0  0.3   5008  3408 ?        Ss   00:03   0:00 /usr/lib/bluetooth/bluetoothd
pi         812  0.0  0.8  42980  7988 ?        Sl   00:03   0:00 /usr/lib/gvfs/gvfs-udisks2-volume-monitor
rtkit      814  0.0  0.2  21376  2080 ?        SNsl 00:03   0:00 /usr/lib/rtkit/rtkit-daemon
root       827  0.0  0.8  59076  7644 ?        Ssl  00:03   0:00 /usr/lib/udisks2/udisksd --no-debug
pi         847  0.0  0.6  42416  6532 ?        Sl   00:03   0:00 /usr/lib/gvfs/gvfs-afc-volume-monitor
pi         857  0.0  0.5  29932  5040 ?        Sl   00:03   0:00 /usr/lib/gvfs/gvfs-mtp-volume-monitor
pi         861  0.0  0.5  30952  5520 ?        Sl   00:03   0:00 /usr/lib/gvfs/gvfs-gphoto2-volume-monitor
pi         867  0.0  0.5  30036  5420 ?        Sl   00:03   0:00 /usr/lib/gvfs/gvfs-goa-volume-monitor
pi         868  0.0  0.0   1912    96 ?        S    00:03   0:00 /bin/sh /usr/bin/start-pulseaudio-x11
pi         869  0.0  0.2   5796  2032 ?        S    00:03   0:00  \_ /usr/bin/xprop -root -spy
pi         956  0.0  0.5  29696  5680 ?        Ssl  00:03   0:00 /usr/lib/menu-cache/menu-cached /tmp/.menu-cached-:0-pi
pi         976  0.0  0.7  60376  7248 ?        Sl   00:03   0:00 /usr/lib/gvfs/gvfsd-trash --spawner :1.1 /org/gtk/gvfs/exec_spaw/0
pi        1009 11.5 12.6 512792 119848 ?       Sl   00:03   0:18 /usr/lib/chromium-browser/chromium-browser --disable-quic --enable-fast-unload --enable-tcp-f
pi        1028  0.0  0.0   3428   856 ?        S    00:03   0:00  \_ /usr/lib/chromium-browser/chrome-sandbox /usr/lib/chromium-browser/chromium-browser --typ
pi        1029  0.1  2.5 169520 24512 ?        S    00:03   0:00  |   \_ /usr/lib/chromium-browser/chromium-browser --type=zygote --ppapi-flash-path=/usr/lib/
pi        1031  0.0  0.7 169520  6684 ?        S    00:03   0:00  |       \_ /usr/lib/chromium-browser/chromium-browser --type=zygote --ppapi-flash-path=/usr/
pi        1069  5.7  8.6 374972 82156 ?        Sl   00:03   0:08  |           \_ /usr/lib/chromium-browser/chromium-browser --type=renderer --enable-pinch --e
pi        1112  8.6 10.4 365288 99056 ?        Sl   00:04   0:12  |           \_ /usr/lib/chromium-browser/chromium-browser --type=renderer --enable-pinch --e
pi        1101  0.3  5.2 248888 49788 ?        Sl   00:03   0:00  \_ /usr/lib/chromium-browser/chromium-browser --enable-features=DocumentWriteEvaluator<Docum
pi        1059  0.0  0.4   9164  4536 ?        S    00:03   0:00 /usr/lib/arm-linux-gnueabihf/gconf/gconfd-2
pi        1164  1.6  1.9  36736 18768 ?        Sl   00:05   0:01 leafpad /home/pi/Desktop/mind/varie.txt
pi        1187  5.7  1.9  47308 18808 ?        Sl   00:06   0:01 lxterminal
pi        1188  0.1  0.1   2348  1528 ?        S    00:06   0:00  \_ gnome-pty-helper
pi        1189  0.9  0.4   6392  4396 pts/0    Ss   00:06   0:00  \_ /bin/bash
pi        1200  0.0  0.2   4896  2228 pts/0    R+   00:06   0:00      \_ ps auxf
and this is the "ps auxf" for manual start

Code: Select all

root         1  0.6  0.4  22968  4016 ?        Ss   00:03   0:03 /sbin/init splash
root       132  0.0  0.3  11904  3128 ?        Ss   00:03   0:00 /lib/systemd/systemd-udevd
root       136  0.1  0.2   9944  2816 ?        Ss   00:03   0:00 /lib/systemd/systemd-journald
root       452  0.0  0.2   5072  2348 ?        Ss   00:03   0:00 /usr/sbin/cron -f
root       454  0.0  0.2   3852  2424 ?        Ss   00:03   0:00 /lib/systemd/systemd-logind
avahi      461  0.0  0.2   3876  2544 ?        Ss   00:03   0:00 avahi-daemon: running [raspberrypi.local]
avahi      468  0.0  0.0   3876   240 ?        S    00:03   0:00  \_ avahi-daemon: chroot helper
message+   462  0.0  0.3   5712  3168 ?        Ss   00:03   0:00 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation
root       466  0.0  0.1   2564  1776 ?        Ss   00:03   0:00 /sbin/dhcpcd -q -b
root       517  0.0  0.3  32144  2876 ?        Ssl  00:03   0:00 /usr/sbin/rsyslogd -n
root       520  0.0  0.3   7156  3380 ?        Ss   00:03   0:00 /sbin/wpa_supplicant -s -B -P /run/wpa_supplicant.wlan0.pid -i wlan0 -D nl80211,wext -c /etc/
root       540  0.0  0.4   7864  4328 ?        Ss   00:03   0:00 /usr/sbin/sshd -D
root       571  0.0  0.7  40520  6932 ?        Ssl  00:03   0:00 /usr/sbin/lightdm
root       663  7.1  7.5 227016 71964 tty7     Rsl+ 00:03   0:32  \_ /usr/bin/X :0 -seat seat0 -auth /var/run/lightdm/root/:0 -nolisten tcp vt7 -novtswitch
root       675  0.0  0.7  32880  7368 ?        Sl   00:03   0:00  \_ lightdm --session-child 13 16
pi         689  0.0  1.2  52380 12232 ?        Ssl  00:03   0:00      \_ /usr/bin/lxsession -s LXDE-pi -e LXDE
pi         719  0.0  0.0   3700   220 ?        Ss   00:03   0:00          \_ /usr/bin/ssh-agent /usr/bin/dbus-launch --exit-with-session x-session-manager
pi         744  0.6  1.2  21060 12116 ?        S    00:03   0:02          \_ openbox --config-file /home/pi/.config/openbox/lxde-pi-rc.xml
pi         747  0.0  0.9  30372  8648 ?        Sl   00:03   0:00          \_ lxpolkit
pi         749  1.2  2.9  97036 27648 ?        Sl   00:03   0:05          \_ lxpanel --profile LXDE-pi
pi         750  0.6  2.7 150932 26268 ?        Sl   00:03   0:02          \_ pcmanfm --desktop --profile LXDE-pi
nobody     638  0.1  0.1   2292  1436 ?        Ss   00:03   0:00 /usr/sbin/thd --daemon --triggers /etc/triggerhappy/triggers.d/ --socket /var/run/thd.socket 
root       652  0.0  0.2   5668  2716 tty1     Ss   00:03   0:00 /bin/login -f   
pi         824  0.0  0.4   6532  4480 tty1     S+   00:03   0:00  \_ -bash
ntp        655  0.0  0.3   5688  3684 ?        Ss   00:03   0:00 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 106:111
pi         683  0.0  0.3   4976  3336 ?        Ss   00:03   0:00 /lib/systemd/systemd --user
pi         686  0.0  0.1   6776  1156 ?        S    00:03   0:00  \_ (sd-pam)         
pi         722  0.0  0.1   3692  1664 ?        S    00:03   0:00 /usr/bin/dbus-launch --exit-with-session x-session-manager
pi         723  0.0  0.2   5608  2128 ?        Ss   00:03   0:00 /usr/bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
pi         729  0.0  0.5  30988  5668 ?        Sl   00:03   0:00 /usr/lib/gvfs/gvfsd
pi         733  0.0  0.5  48524  5212 ?        Sl   00:03   0:00 /usr/lib/gvfs/gvfsd-fuse /run/user/1000/gvfs -f -o big_writes
root       755  0.0  0.7  40956  7276 ?        Ssl  00:03   0:00 /usr/lib/policykit-1/polkitd --no-debug
pi         761  0.0  0.0   3700   220 ?        Ss   00:03   0:00 /usr/bin/ssh-agent -s
root       766  0.0  0.0   2068   148 ?        S    00:03   0:00 /usr/bin/hciattach /dev/serial1 bcm43xx 921600 noflow -
root       780  0.0  0.3   5008  3408 ?        Ss   00:03   0:00 /usr/lib/bluetooth/bluetoothd
pi         812  0.0  0.8  42980  7988 ?        Sl   00:03   0:00 /usr/lib/gvfs/gvfs-udisks2-volume-monitor
rtkit      814  0.0  0.2  21376  2080 ?        SNsl 00:03   0:00 /usr/lib/rtkit/rtkit-daemon
root       827  0.0  0.8  59076  7644 ?        Ssl  00:03   0:00 /usr/lib/udisks2/udisksd --no-debug
pi         847  0.0  0.6  42416  6532 ?        Sl   00:03   0:00 /usr/lib/gvfs/gvfs-afc-volume-monitor
pi         857  0.0  0.5  29932  5040 ?        Sl   00:03   0:00 /usr/lib/gvfs/gvfs-mtp-volume-monitor
pi         861  0.0  0.5  30952  5520 ?        Sl   00:03   0:00 /usr/lib/gvfs/gvfs-gphoto2-volume-monitor
pi         867  0.0  0.5  30036  5420 ?        Sl   00:03   0:00 /usr/lib/gvfs/gvfs-goa-volume-monitor
pi         868  0.0  0.0   1912    96 ?        S    00:03   0:00 /bin/sh /usr/bin/start-pulseaudio-x11
pi         869  0.0  0.2   5796  2032 ?        S    00:03   0:00  \_ /usr/bin/xprop -root -spy
pi         956  0.0  0.5  29696  5680 ?        Ssl  00:03   0:00 /usr/lib/menu-cache/menu-cached /tmp/.menu-cached-:0-pi
pi         976  0.0  0.7  60376  7248 ?        Sl   00:03   0:00 /usr/lib/gvfs/gvfsd-trash --spawner :1.1 /org/gtk/gvfs/exec_spaw/0
pi        1009 10.2 13.5 533072 128036 ?       Sl   00:03   0:45 /usr/lib/chromium-browser/chromium-browser --disable-quic --enable-fast-unload --enable-tcp-f
pi        1028  0.0  0.0   3428   856 ?        S    00:03   0:00  \_ /usr/lib/chromium-browser/chrome-sandbox /usr/lib/chromium-browser/chromium-browser --typ
pi        1029  0.0  2.5 169520 24512 ?        S    00:03   0:00  |   \_ /usr/lib/chromium-browser/chromium-browser --type=zygote --ppapi-flash-path=/usr/lib/
pi        1031  0.0  0.7 169520  6748 ?        S    00:03   0:00  |       \_ /usr/lib/chromium-browser/chromium-browser --type=zygote --ppapi-flash-path=/usr/
pi        1069  2.4  8.7 374972 83164 ?        Sl   00:03   0:10  |           \_ /usr/lib/chromium-browser/chromium-browser --type=renderer --enable-pinch --e
pi        1112 52.3 12.6 381636 119984 ?       Rl   00:04   3:43  |           \_ /usr/lib/chromium-browser/chromium-browser --type=renderer --enable-pinch --e
pi        1101  0.1  5.2 248888 49788 ?        Sl   00:03   0:00  \_ /usr/lib/chromium-browser/chromium-browser --enable-features=DocumentWriteEvaluator<Docum
pi        1059  0.0  0.4   9164  4536 ?        S    00:03   0:00 /usr/lib/arm-linux-gnueabihf/gconf/gconfd-2
pi        1164  0.3  1.9  36736 18768 ?        Sl   00:05   0:01 leafpad /home/pi/Desktop/mind/varie.txt
pi        1229  8.2  2.0  47184 19048 ?        Rl   00:09   0:07 lxterminal
pi        1230  0.0  0.1   2348  1456 ?        S    00:09   0:00  \_ gnome-pty-helper
pi        1231  0.2  0.4   6400  4580 pts/0    Ss   00:09   0:00  \_ /bin/bash
pi        1249 18.0  0.6  29536  6436 pts/0    Sl+  00:09   0:13  |   \_ puredata /home/pi/Desktop/mind/pd/audio.pd
pi        1250  0.0  0.0   1912   368 pts/0    S+   00:09   0:00  |       \_ sh -c TCL_LIBRARY="/usr/lib/puredata/lib/tcl/library" TK_LIBRARY="/usr/lib/pureda
pi        1252 27.9  2.4  36888 22916 pts/0    Sl+  00:09   0:21  |       |   \_ wish /usr/lib/puredata/tcl//pd-gui.tcl 5400
pi        1251  0.0  0.0   1912   384 pts/0    S+   00:09   0:00  |       \_ sh -c /usr/lib/puredata/bin/pd-watchdog
pi        1253  0.0  0.0   1840   392 pts/0    S+   00:09   0:00  |           \_ /usr/lib/puredata/bin/pd-watchdog
pi        1328  0.4  0.4   6400  4536 pts/1    Ss   00:10   0:00  \_ /bin/bash
pi        1342 74.9  1.6  35348 16016 pts/1    Rl+  00:10   0:21  |   \_ python /home/pi/Desktop/mind/python/test1.py
pi        1346  1.2  0.4   6392  4336 pts/2    Ss   00:10   0:00  \_ /bin/bash
pi        1355  0.0  0.2   4896  2300 pts/2    R+   00:11   0:00      \_ ps auxf
still when running autostart the amount of CPU is much higher than with manual start
CarlRJ wrote: And in the case of the Mindwave script (at least), if you have "#!/usr/bin/env python" as the first line, and set the execute bit on the script (once) with "chmod a+x /home/pi/python/Mindwave/test1.py", then you don't need to say "python" in front of it, you can run it as a "first class citizen" on the system (that specially crafted first line tells the kernel how to go about executing the script, and the execute bit in the script's permissions tell the kernel that the file is something it can try to execute).
I did this but I still need to run it as python /home/pi/Desktop/mind/python/test1.py from the terminal (otherwise it just says command not found )
CarlRJ wrote:
I hope I don't sound too abrupt, in all of this. I apologize if I come across that way. I don't mean to be. Just trying to get a lot of details across in a hurry.
not at all! You are being VERY helpful. I'm a total beginner with Linux world and I'm learning a lot! (today I think I messed up something and I didn't know how to fix so I flashed the sd and the names of the folders of my scripts are different)

Thank you

plasticus
Posts: 34
Joined: Tue Nov 01, 2016 10:31 pm

Re: start script via bash = huge CPU drain

Wed Feb 01, 2017 6:14 am

I will resume this topic.
I fixed the issue above, now I have a CPU usage of 38-40% whit the script in autostart. However I find it weird that with this low usage the temperature is about 87-88 degrees (with 2 heatsinks). What happened after about 3 hours of running like this is that the rasp is now burned as it just shut itself down and it doesn't start anymore (sd card looks fine). I honestly don't really understand how a single script consuming only 40% of cpu can overheat that much. any suggestions about what to do before I burn my new one as well? I can post the whole running script which is just a python script reading from serial port anyway..

Return to “General discussion”