View current kernel parameters?
Solution 1
So one of the big things about learning to Unix is reading the bloody man page:
I'm not just being a get off my lawn grumpy old man, there REALLY IS valuable information in there. In this case:
DESCRIPTION sysctl is used to modify kernel parameters at runtime. The parameters available are those listed under /proc/sys/. Procfs is required for sysctl support in Linux. You can use sysctl to both read and write sysctl data.
So we can:
$sudo sysctl -a | grep kernel.perf_event_max_sample_rate
kernel.perf_event_max_sample_rate = 50000
sysctl: reading key "net.ipv6.conf.all.stable_secret"
sysctl: reading key "net.ipv6.conf.default.stable_secret"
sysctl: reading key "net.ipv6.conf.enp3s0.stable_secret"
sysctl: reading key "net.ipv6.conf.lo.stable_secret"
sysctl: reading key "net.ipv6.conf.wlp1s0.stable_secret"
By reading the manpage we learn that -a is "display all values currently available", but we also can see:
SYNOPSIS
sysctl [options] [variable[=value]] [...]
sysctl -p [file or regexp] [...]
which means we can shorten the above command to:
$ sudo sysctl kernel.perf_event_max_sample_rate
kernel.perf_event_max_sample_rate = 50000
Or we can:
$ more /proc/sys/kernel/perf_event_max_sample_rate
50000
So, TL;DR:
Yes, you can write a script to log this variable every few minutes, but if it's going to show up in the logs when it changes, why would you?
It would probably be more efficient to read the value right out of /proc/sys/kernel/perf_event_max_sample_rate than to use sysctl, and it would be more efficient to ask for the specific value from sysctl than to use grep.
Solution 2
If you read the manpage of systctl you also see that systctl is just a mirror of /process/sys. So you don't need any command to change the systctl value. Just run
echo $value > /proc/sys/$sysctl_setting
Just beware to replace *.*with / in this case.
Loop this in a while loop like this:
sleep_time=10m
while true ; do
echo $value > /proc/sys/$sysctl_setting
sleep $sleep_time
done
Related videos on Youtube
pwnyrainbow
Updated on September 18, 2022Comments
-
pwnyrainbow over 1 year
I saw in my syslog
kernel.perf_event_max_sample_rate
get changed.I was wondering if I could write a quick script to log this variable every few minutes. Currently it is:
sysctl -a | grep kernel.perf_event_max_sample_rate
In the man page sysctl says
sysctl
- configure kernel parameters at runtimeDoes that mean that my script would get the parameter as it was set when the kernel starts? Would it pick up changes?
-
pwnyrainbow over 8 yearsThanks, I see now there are things I overlooked. My question was really my interpretation of 'at runtime' being now or when it started. Which appears to be what it is set to at the moment.