Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Linux system information in C

Tags:

c

linux

bash

I have to check Linux system information. I can execute system commands in C, but doing so I create a new process for every one, which is pretty expensive. I was wondering if there is a way to obtain system information without being forced to execute a shell command. I've been looking around for a while and I found nothing. Actually, I'm not even sure if it's more convenient to execute commands via Bash calling them from my C program or find a way to accomplish the tasks using only C.

like image 441
user3574984 Avatar asked Sep 18 '25 00:09

user3574984


1 Answers

Linux exposes a lot of information under /proc. You can read the data from there. For example, fopen the file at /proc/cpuinfo and read its contents.

like image 156
Tom van der Woerdt Avatar answered Sep 20 '25 15:09

Tom van der Woerdt