How to create a Kernel panic in RHEL without rebooting after panic - linux

I need to create kernel panic and I tried following
sysctl kernel.panic=0 && echo c > /proc/sysrq-trigger
When I ran the commands above. I see system always reboots. I need system to be in panic mode without rebooting

Use -w option when you want to change a sysctl setting under RHEL.
Multiple commands example:
> sysctl -w kernel.panic="0"
> echo c > /proc/sysrq-trigger
Notice that if you want to preserve kernel settings after reboot, it's always better to add them to the /etc/sysctl.conf file. However the quickly setting method maybe enough for your testing requirments.
Also make sure you don't paste both commands "sysctl -w kernel.panic=0 echo c > /proc/sysrq-trigger" together. (I'm always giving this recommendation when i see multiple shell commands posted together, like i see in your question). Or use && operator to execute the next command like this:
Single line example:
sysctl -w kernel.panic="0" && echo c > /proc/sysrq-trigger

Related

Reset /proc/sys/vm/drop_caches to default value 0

Recently I tried to empty the buffers cache on a Debian webserver. The command I used was:
free && sync && echo 3 > /proc/sys/vm/drop_caches && free
So far so good, running cat /proc/sys/vm/drop_caches prints a value of 3.
When I try to reset the value to 0 with sync && echo 0 > /proc/sys/vm/drop_caches, this error shows:
bash: echo: write error: Invalid argument
Which is due to drop_caches being a command, not a variable to be set. I found this:
sudo sysctl -w vm.drop_caches=3
It immediately clears the pagecache, dentries and inodes and clears again only if you call sysctl -w again, there is no need to apparently set it back to 0 in an explicit manner. The command sysctl is not natively supported on Debian so I'm looking for an alternative command, more precisely:
How to reset drop_caches or immediately empty the cache to reset the value to 0?
The values 1-3 are just one time trigger for action. There is no value 0.
sysctl is in package procps .
apt install procps
To disable them, echo 4 (bit 2) into drop_caches.
from https://www.kernel.org/doc/Documentation/sysctl/vm.txt

OSX Mojave sysctl -p illegal

14 "Mojave" on my macbook and I am trying to increase the fs.inotify.max_user_watches value in /etc/sysctl.conf (to solve another problem). To conclude this rite I need to run sudo sysctl -p /etc/sysctl.conf. But I get
"illegal option -- p"
When I check the man page on osx it in fact does not have the -p option (to supply a file) nor the --system option (to load all known config files); on another system I clearly see that those options are available.
How else then can I get sysctl to take my new configs? Is there a different way to configure fs.inotify.max_user_watches on osx?
On Big Sur, the first lines for sysctl manpage are:
SYSCTL(8) BSD System Manager's Manual SYSCTL(8)
NAME
sysctl -- get or set kernel state
This must mean sysctl itself can be used to update some values. However, sysctl does not show the fs.inotify.max_user_watches name. Must be another mac thing...

How to detect if i3-wm is being run or GNOME is being run in bash

I've been using i3-wm for about six months now, and I had to switch to GNOME because Discord was crashing a lot in i3. I had previously used the i3-msg command in my bashrc to make sure the borders of the terminal wouldn't be visible, as to use the entire screen space for the terminal. The specific command I run is:
i3-msg -q border toggle
The problem is, when I use GNOME and I open up a terminal, the i3-msg command runs, and causes an error message evidently caused by the fact that i3 isn't running. The ideal scenario would be to add an if statement that checks if i3 is running, and if it is, then run the i3-msg command.
My question: What is the most convenient way to determine which window manager / Desktop Environment is currently running in my system?
When i3 is active, there should be a proces called "i3". You could check that with pgrep.
if pgrep -x "i3" > /dev/null
then
echo "i3 is running"
fi
-x is short for --exact – without it the if clause would still work, as long as no non-i3 process' name contains i3.
Omitting > /dev/null would print out the pid(s) found by pgrep.
Instead of pgrep you could also use pidof or ps -C. Instead of idiomatic if-then-fi you could also just use && like pidof i3 > /dev/null && echo "i3 is running" || echo "i3 is not running"

modify kernel parameters in linux without using sysctl

I have an embedded system. An old linux OS runs on it. When i enter "uname -r" command i get the version information as "3.3.8-3.4".
I want to modify some of network kernel parameters (increase tcp receive buffer size etc.) in /proc/sys. But sysctl command does not exist in this old linux kernel version. Also sysctl.conf does not exist under /etc directory
I tried changing kernel parameter files manually but system does not allow this operation even for super user.
How can i modify kernel parameters in this linux version?
You can use /proc/sys. For example the following command:
echo 1 > /proc/sys/net/ipv4/ip_forward
... is basically the same as
sysctl -w net.ipv4.ip_forward=1
However, you'll need to make sure on your own that parameters will be set on boot.

Parallel make: set -j8 as the default option

I can set number of threads for the build process using -j argument. For example, I have 4 cores +4 virtual. When I write: make -j8 the speed increases 4 times.
Is it possible to set that value as default? (For example, in Linux Gentoo, in config file, it's possible to set this default value).
p.s. I have Arch Linux
Your question is not about threads, but processes (jobs) executed by make.
The simple, way to set this, when make is used from the console is adding:
alias make="/usr/bin/make -j 8"
to your .profile file.
You can also use setenv MAKEFLAGS '-j 8', but MAKEFLAGS can ignore this parameter in some scenarios, because keeping desired number of processes requires communicating with recursive make calls. Happily this method works with current versions of GNU Make.
setenv MAKEFLAGS '-j8'
Hope this helps!
Here's how I've done it:
CORES ?= $(shell sysctl -n hw.ncpu || echo 1)
all:; #$(MAKE) _all -j$(CORES)
_all: install lint test
.PHONY: all _all
…
I've basically "aliased" my default target all to a "private" _all. The command to figure out the number of cores is OSX specific, AFAIK, so you could just improve it to be more cross platform if you will. And because of the ?= assignment, we can just override it with and env variable if/when needed.
EDIT:
You can also append to your MAKEFLAGS from within the makefile itself, like so:
CPUS ?= $(shell sysctl -n hw.ncpu || echo 1)
MAKEFLAGS += --jobs=$(CPUS)
…
EDIT 2:
You may also use the following, ff you want it to be more cross-platform:
CPUS ?= $(shell (nproc --all || sysctl -n hw.ncpu) 2>/dev/null || echo 1)

Resources