Skip to main content

Mining Bitcoins with Raspberry Pi - Part 2

·396 words·2 mins
tech bitcoin cgminer cryptocurrency debian iot linux raspberry-pi raspbian technology
James Pettigrove
Author
James Pettigrove
Cloud Engineer with a focus on Microsoft Azure
Mining Bitcoins with Raspberry Pi - This article is part of a series.
Part 2: This Article

In a previous post, we covered how to setup your Raspberry Pi with cgminer along with some USB ASIC mining hardware.

So now that we have cgminer working just the way we want to, why not go one step further and run cgminer as a background process (i.e. a service) so even if you close your session your miners will continue to hum away at those hashes? The beauty about Linux is any process can be sent into the background using a combination of nohup and >/dev/null 2>&1& as below

sudo nohup ./cgminer --config /path/to/config.conf >/dev/null 2>&1&

Let’s break this down so we know exactly what is going on;

nohup

will block any command from receiving the hangup signal which is sent out to all processes in a shell upon termination (say, when you log out)

>/dev/null

will send any standard output from the command to the blackhole known as /dev/null

2>&1

will send any standard output errors (so any errors) to standard output, which is going to /dev/null

&

will run the command as a child process of your current session

Easy right? …..mmmmm no

Due to the nature of cgminer and the interface it outputs, sending the output to /dev/null makes it go all crazy on the Raspberry Pi’s CPU.

Go ahead and run the following to check the processes running on your Pi

top

You will most likely experience something like the below:

Check out that cpu usage by cgminer… 93.2%

It won’t be long before your poor Pi is crying in agony (passively cooled and stressed is not a combination I would want to occur for any stretch of time)

Let’s stop cgminer by taking note of the number under the PID column for cgminer and running the following

sudo kill replacewithpid

or in my instance

sudo kill 11851

Now that our Pi is back to normal let’s try making cgminer a background process once more but with a couple of extras added in

sudo nohup ./cgminer --compact --real-quiet --config /path/to/config.conf >/dev/null 2>&1&

--compact removes the mining device statistics

--real-quiet disable’s all output (not strictly true, but close enough)

If we check with top once more you will find cgminer happily ticking away at around 10% CPU usage. Much more bearable.

Tune in to the final part where we will turn that background process into one that autostart’s with your Raspberry Pi

Mining Bitcoins with Raspberry Pi - This article is part of a series.
Part 2: This Article

Related

Mining Bitcoins with Raspberry Pi - Part 1
·537 words·3 mins
tech bitcoin cgminer cryptocurrency debian iot linux raspberry-pi raspbian technology
Continuing with my last post’s theme surrounding my recently received Raspberry Pi; after the initial configuration, I put it into action by mining Bitcoins with some Aussie USB ASIC miners I purchased of eBay for $36 (for two).
Raspberry Pi A+
·215 words·2 mins
tech iot linux raspberry-pi raspbian technology
Christmas brought me a very special gift in the form of a Raspberry Pi A+
Pi Computing
·236 words·2 mins
tech edx intel-nuc iot raspberry-pi technology
Really starting to dig the RaspberryPi at the moment.