Can I somehow pause all processes of an user logged in in background?
Solution 1:
One way would be to send the SIGSTOP
signal to all of your brother's processes:
sudo pkill -STOP -u brother
To awaken the stopped processes, the SIGCONT
signal is used:
sudo pkill -CONT -u brother
You can use an Upstart session job, one which would run when you logged in or out or locked or unlocked your screen. For example, create a .conf
file in ~/.config/upstart
(say ~/.config/upstart/stop-brother.conf
) containing:
description "Stop all my brother's processes"
start on desktop-start or desktop-unlock
task
exec sudo pkill -STOP -u brother
And a converse file (say ~/.config/upstart/start-brother.conf
) containing:
description "Resume all my brother's processes"
start on desktop-end or desktop-lock
task
exec sudo pkill -CONT -u brother
You also need a NOPASSWD
entry in sudoers
:
sudo tee /etc/sudoers.d/stop-brother <<EOF
$USER ALL = (ALL) /usr/bin/pkill -STOP -u brother, /usr/bin/pkill -CONT -u brother
EOF
Now the signals should be sent automatically when you log in, log out, lock or unlock the screen. You can manually initiate either using:
start stop-brother
start start-brother
Solution 2:
Check which application is taking higher resources.
Find the pid of that application using the command
pidof "application name"
without the quotes.
sudo kill -STOP "ID of the process"
Then once you have completed your work use the below command to start that stopped process.
sudo kill -CONT "PID that you have killed earlier"
Give it a try!
Solution 3:
Check this Save and Restore Linux Processes with CRIU