3

I have mainly two accounts on my 14.10 laptop: Mine (admin) and my brother's (restricted).

Now when my brother is logged in and runs some applications like firefox with flash player, it consumes much CPU. I have an Intel 2GHz, 2 cores, but with software rendering because of half-broken graphics card.
When he now locks his account and I log into mine, CPU is at about 80% even if I do nothing. indicator-multiload shows firefox and compiz of the other user as most consuming processes, sometimes xorg too, I think.

So in a nutshell: Can I run a command/script to pause the processes started by another user and resume them again after I have done my work? Would be nice if that could be executed at every locking/login/logout.

But is this safe for all applications? Where do I have to pay attention?

9
  • 1
    Try pkill -STOP -u brother.
    – muru
    Feb 18, 2015 at 21:10
  • @muru But doesn't this kill the processes? I want that he is able to continue whatever he was doing when he logs back in. How do I pause and resume processes? And does this automatically work on all of his processes or is there more scripting needed? And is it safe or might some apps crash and lead to data loss or kill the whole system?
    – Byte Commander
    Feb 18, 2015 at 21:21
  • A similar question on U&L: how-can-i-pause-resume-rsync, but I am not really sure how to apply this to my own problem.
    – Byte Commander
    Feb 18, 2015 at 21:24
  • To apply that, you do pkill -STOP -u brother, or pkill -u TSTP -u brother, if you're feeling polite. You could refine a bit, say specifying firefox or Xorg, if you feel like it..
    – muru
    Feb 18, 2015 at 21:26
  • @muru And if I only give the -u parameter, it works on all processes of that user? But is this really safe or might some apps crash (especially those accessing files or things like compiz and xorg)?
    – Byte Commander
    Feb 18, 2015 at 21:39

3 Answers 3

7

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
3
  • 1
    Comments are not for extended discussion; this conversation has been moved to chat.
    – RolandiXor
    Feb 20, 2015 at 17:50
  • @RolandiXor We (= @Fabby) already have opened a chat room for this question. It is called "Sleep, brother sleep". Could you merge those two, please?
    – Byte Commander
    Mar 1, 2015 at 19:31
  • Sure! Next time, please flag the question before the system kicks in to flag it ;)
    – RolandiXor
    Mar 2, 2015 at 15:07
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!

1
  • 1
    Thanks! It works, but I prefer @muru's solution, because it is only one command for all processes. So upvoted, but not accepted.
    – Byte Commander
    Feb 20, 2015 at 12:41
1

Check this Save and Restore Linux Processes with CRIU

1
  • 1
    Thanks for your answer, but it would be nice if you could improve it by adding a summary of the article you linked. Because sometimes links become dead and then your answer loses its sense. Also the people who are having this problem must follow the link and switch tabs and read through a long article. So please improve your answer and you will also get some upvotes. Thanks :-D
    – Byte Commander
    Feb 19, 2015 at 14:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .