Check free disk space

I have to do a program that log some strings received from a input (at this time is indifferent, but the input devices are serial ports) until the disk is full…

there is a way to know when the disk is full or how much free space I have on it?

think that log files are wrote at different times(so can’t use write() and check for ENOSPC because I must know the disk status immediatly after the boot…

There is the ‘df’ command.

yes I know. But How can use it inside a C program for check free space not just outputting on the screen but storing (for example) on a var?

Perhaps statvfs() is what you are after, man page is on



ok thanks

You can read the output from a programm with the popen() command.