Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 19 Jan 2020 06:41:51 +0100
From:      Polytropon <freebsd@edvax.de>
To:        Ihor Antonov <ihor@antonovs.family>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: sysctl and /sysfs
Message-ID:  <20200119064151.7f781748.freebsd@edvax.de>
In-Reply-To: <4538784.31r3eYUQgx@t800>
References:  <4538784.31r3eYUQgx@t800>

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help
On Sat, 18 Jan 2020 20:27:27 -0800, Ihor Antonov wrote:
> Hi everyone,
> 
> I am coming to FreeBSD from Linux and I have questions about
> system structure.
> 
> I noticed that FreeBSD makes heavy use of `sysctl` to read and
> write kernel 
> parameters. Linux has /proc and /sys filesystems that represent
> various kernel 
> data structures, some of which could be writable.
> 
> In the spirit of Unix philosophy "everything is a file" [...]

In context of Linux...

https://www.youtube.com/watch?v=9-IWMbJXoLM#t=8m20s

Sorry, couldn't resist. ;-)



> [...] I was wondering if 
> FreeBSD provides a view into kernel's parameters similar to
> sysfs on linux?

I hope not. :-)



> It feels a bit strange that instead of naturally exposing
> hierarchical kernel 
> data structures in a form of filesystem one has to use sysctl
> and text values 
> in a "parend.child.subchild" pattern. So the question is why?

The primary reason is that this is historically grown, and
brought forward through decades of kernel and system parts
development.



> It is possible that I am missing something or maybe FreeBSD has
> a different 
> view on this problem - I would love to understand! 

The core "problem" (which actually isn't a problem at all)
is that exposing _everything_ as a file or a hierarchical
filesystem doesn't seem to work for each and every case.
That's why different approaches have been taken that worked
out in a better way. With sysctl, direct access to kernel
system information has been unified. There is still some
kind of hierarchy preserved.

See "man 3 sysctl" and "man 1 sysctl" for details.



Sidenote:

Watching "What UNIX Cost Us" by Benno Rice at "linux.conf.au"
(LCA) 2020 does actually help understanding _why_ the use of
the "everything is a file" metaphor doesn't always work.



-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...



Want to link to this message? Use this URL: <http://docs.FreeBSD.org/cgi/mid.cgi?20200119064151.7f781748.freebsd>