Kitcha
Kitcha

Reputation: 1731

How to read the disk usage (du) in a C variable

I would like to do the following in a "c" program.

I need to get the disk usage of the following directory and should be able to read it in a variable.

du -sb /home/mann | awk '{print$1}'

I would like to do the above in C program and copy the output in a variable. I need to do this for this directory alone not for the "/" or "/home".

Upvotes: 0

Views: 1265

Answers (1)

parapura rajkumar
parapura rajkumar

Reputation: 24403

  • Pipe the output of your command to a file on the disk. Run your command using system
  • Read the file using standard C functions
  • Update your variable

Another option is to use popen/pclose to launch your command. This will return a file descriptor from which you can read.

Yet another option is to hunt your system for any library function that provides the information you desire

Upvotes: 2

Related Questions