I would like to check if my hard drive is active or not and set a variable or boolean to use later in the program. I have hdparm installed and working properly to spin down the drive after a set period of time. The drive is on /dev/sda2 and automounts at boot.
I read about popen()
but am still not great with parsing outputs in c. Is there another way to do this?
Alternatively checking if it is in standby mode will work also.
You can just read from "/sys/block/sda2/stat". For documentation see https://www.kernel.org/doc/Documentation/block/stat.txt. You program should work like this: