PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, September 18, 2022

[FIXED] How does the command 'echo "6" > /proc/sys/kernel/printk' work?

 September 18, 2022     file, linux, linux-kernel, printing, shell     No comments   

Issue

Please see an example in How can I show printk() message in console?,

$ cat /proc/sys/kernel/printk
4 4 1 7
$ echo "6" > /proc/sys/kernel/printk
$ cat /proc/sys/kernel/printk
6 4 1 7

If the /proc/sys/kernel/prink was a normal file, the file would have changed to just "6", a single number. But I know the proc file system is a file system in ram and I guess it works different. In what mechanism did the file changed that way? And if I wanted to change the content to 4 6 1 7, can I do it with echo command and redirection?


Solution

Filesystem entries under /proc behave somewhat like function calls. "Writing" a string to the file is like calling a function with the string as an argument. "Reading" from the file is like calling a function with no argument and getting back the return value. The behavior of each "function" is defined by the kernel (or at least, by the proc file system exposed by the filesystem entries).

See https://www.kernel.org/doc/html/latest/core-api/printk-basics.html for the details on how printk in particular works. In short, writing a number to the file changes the current logging level, while reading shows the current (if changed), default, minimum, and boot-time default logging levels.



Answered By - chepner
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing