Quote:
Originally posted by gearoid
how do I access system variables (e.g. username, date, kernel version, etc. etc.) from a c++ program?
|
You can get this info mainly from the files and directories in /proc. All programs like ps, uname, top, free, vmstat, etc. read their information from the files in /proc.
Just read and parse the information from the files in /proc, or e.g. to see who is the owner of PID 850, call stat() on the file /proc/850.
See "man proc" for more info about the format of the files in /proc.
Maybe also read "man utmp" for info about users logging in and out.
Quote:
Or could I just fork and exec these shell commands from my c++ program??
|
Yes, that would work also. But it's ugly and inefficient. Use popen() (or some C++ equivalent if it exists) instead of fork() and the exec() family of functions.