A chatty service waking every few milliseconds is burning power for nothing, and /proc/<pid>/timerslack_ns is the file that fixes it. In this walkthrough you read a thread's current timer slack, change it for a controlled test, verify the new nanosecond value, and restore its default. Allow about 10 minutes. You need a Linux system with procfs mounted and a shell; the examples use Bash built-ins so that /proc/self keeps referring to the shell doing the operation.
/proc/<pid>/timerslack_ns exposes the current timer slack for a process, measured in nanoseconds. Timer slack lets the kernel group timer expirations that are close together. A larger value can reduce wake-ups and power use, but a timer affected by slack may expire late by up to the specified amount. It does not make a timer expire early.
The interface has existed since Linux 4.6. The setting is associated with each thread. A new thread starts with values copied from its creator, and the value survives an execve. This means a change made in a long-running shell or service can affect children created afterwards.
The installed local manpage is from Linux man-pages 6.7, package version 6.7-2. The running kernel here is 6.8.0-139-generic. Kernel support and access policy still matter more than the manpage package version.
Start with the process you control. In Bash, use a shell variable to keep the target process stable while the read and printf built-ins access the file:
before=''
IFS= read -r before < /proc/self/timerslack_ns
printf 'current timer slack: %s ns\n' "$before"
Expected output is one decimal number, such as:
current timer slack: 50000 ns
Do not replace this with cat /proc/self/timerslack_ns when diagnosing a shell. /proc/self means the process that opens the path, so an external cat refers to cat, not necessarily the shell you meant to inspect. For another process, replace self with its numeric PID.
Checkpoint: keep the value from the first command. Writing zero later restores the thread's default timer slack, which may not be the same as the current value you recorded.
Use a deliberately visible one-millisecond value for a short-lived test shell. One millisecond is 1,000,000 nanoseconds:
after=''
printf '1000000\n' > /proc/self/timerslack_ns
IFS= read -r after < /proc/self/timerslack_ns
printf 'changed timer slack: %s ns\n' "$after"
Expected output:
changed timer slack: 1000000 ns
This changes the shell running the commands and can be inherited by processes it starts. It does not set a system-wide policy. Keep the value positive. The related prctl(2) interface documents 1 as the minimum current value and ULONG_MAX as the maximum; the proc file accepts the decimal value in nanoseconds.
Writing zero resets the current value to that thread's default:
reset=''
printf '0\n' > /proc/self/timerslack_ns
IFS= read -r reset < /proc/self/timerslack_ns
printf 'restored timer slack: %s ns\n' "$reset"
On a typical shell descended from PID 1, the result is 50000 ns, or 50 microseconds. Treat that as an observation, not a universal constant: the current value can be inherited, and the default depends on the thread's ancestry. If you need to preserve an intentional non-default setting rather than reset it, write the saved decimal value from your baseline instead.
For a target PID, substitute an actual number and read its file:
TARGET_PID=12345
cat "/proc/$TARGET_PID/timerslack_ns"
Reading or writing another process's file is subject to procfs permission checks. Since Linux 4.9, the documented capability for this interface is CAP_SYS_NICE, rather than the stronger CAP_SYS_PTRACE check used initially. A permission error is not fixed by changing the path to /proc/self if the target is genuinely another process.
Changing a service's value can alter its latency and wake-up behaviour. Make the change reversible, identify the service owner, and record the old value before writing. Do not experiment on a critical service or PID 1 without a rollback plan. Elevated privileges are not needed for the shell example or for a process you can already access; use only the minimum privilege needed for a different target.
/proc/self follows the opener. Pin a target with its numeric PID when inspecting a service, and use shell built-ins for a shell-local test.prctl(2), and does not turn arbitrary scheduling or real-time behaviour into ordinary timer slack.