# How to access kernel variable in c program



## Logan89 (Feb 27, 2013)

Hello,

Can anyone help me and tell how to access a kernel variable from in a c source code?

For example, the command *sysctl -A* returns a list of variables and I need to access one of them in my c source file.

Thank you.


----------



## expl (Feb 27, 2013)

sysctlbyname(3)


----------



## Logan89 (Feb 27, 2013)

Is there any other way because sysctl() appears in FreeBSD 4.4 and I am looking for an older version


----------



## expl (Feb 27, 2013)

Logan89 said:
			
		

> Is there any other way because sysctl() appears in FreeBSD 4.4 and I am looking for an older version



Can you be more specific when referring to older version? You can always check source code for 'sysctl' command on the FreeBSD version you are interested in, to see what routines it uses to get the values.


----------

