View previous topic :: View next topic |
Author |
Message |
josephg l33t
Joined: 10 Jan 2016 Posts: 783 Location: usually offline
|
Posted: Fri Feb 16, 2018 1:59 pm Post subject: shell script suspend/resume child processes |
|
|
i would like to run a shell script which will auto suspend itself (or child processes) when loadavg>2 and auto resume when loadavg<2. is this possible?
edit: changed 1 to 2.. could be x. _________________ "Growth for the sake of growth is the ideology of the cancer cell." Edward Abbey
Last edited by josephg on Fri Feb 16, 2018 11:17 pm; edited 2 times in total |
|
Back to top |
|
|
Naib Watchman
Joined: 21 May 2004 Posts: 6051 Location: Removed by Neddy
|
Posted: Fri Feb 16, 2018 2:18 pm Post subject: |
|
|
um... assuming a script could still run when your machine is suspended (negating the concept of suspend). The moment it suspends load < 1 --> would auto un-suspend
This stinks of an x-y problem.. what are you trying to solve. _________________
Quote: | Removed by Chiitoo |
|
|
Back to top |
|
|
Zucca Moderator
Joined: 14 Jun 2007 Posts: 3342 Location: Rasi, Finland
|
Posted: Fri Feb 16, 2018 2:35 pm Post subject: |
|
|
Naib wrote: | The moment it suspends load < 1 --> would auto un-suspend | Yeah. It definitedly needs some threshold. And maybe some delays...
It's an interesting idea. Doable using sh. Polling /proc/loadavg maybe... _________________ ..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote: | I am NaN! I am a man! |
|
|
Back to top |
|
|
josephg l33t
Joined: 10 Jan 2016 Posts: 783 Location: usually offline
|
Posted: Fri Feb 16, 2018 10:36 pm Post subject: |
|
|
Naib wrote: | assuming a script could still run when your machine is suspended |
i didn't mean power suspend the machine, just runtime suspend the shell script or any called child process(es), something like job control perhaps.
Naib wrote: | This stinks of an x-y problem.. what are you trying to solve. |
one of my potential problems is emerge. i'm not sure emerge respects --load-avg=2 on my gentoo. i find, particularly while compiling a large package, that loadavg shoots up to double digits sometimes. and then i ctrl+z so i can continue working.. i can activate suspended process later.
i'm not always online, and always power off after i've finished. the past two weeks my laptop has been churning emerge continously for a few big packages. and i have hit this issue as i'm trying to get something done and my machine goes awol.
there are other times when some other program (like spotify) is running away. i was thinking perhaps i could run it from a shell script and monitor loadavg.
Zucca wrote: | Yeah. It definitedly needs some threshold. And maybe some delays...
It's an interesting idea. Doable using sh. Polling /proc/loadavg maybe... |
threshold could be whatever reasonable, perhaps the number of cpu on my system. i currently poll /proc/loadavg on my tmux status line and also on my i3status. that's how i have an understanding of when my machine starts misbehaving.. loadavg shoots up into double digits and keeps going up. i have identified a few errant programs.
Last edited by josephg on Sat Feb 17, 2018 1:03 am; edited 1 time in total |
|
Back to top |
|
|
Hu Moderator
Joined: 06 Mar 2007 Posts: 21622
|
Posted: Sat Feb 17, 2018 12:26 am Post subject: |
|
|
man emerge: | --load-average [LOAD]
Specifies that no new builds should be started if there are
other builds running and the load average is at least LOAD (a
floating-point number). | Per that wording, once a build is running, it can achieve theoretically unlimited load and the only response Portage will make is not to start more builds until the load average comes down. Portage will not suspend the processes from the already running ebuild. For your case of --load-avg=2, if load average falls below that, Portage can start more ebuilds running, even if any single started ebuild will, during its heavy lifting phase, drive load average well above 2. Based on your description, I think you should not use --load-avg to start multiple ebuilds in parallel, except in cases where you know that all the ebuilds to run will be relatively lightweight. |
|
Back to top |
|
|
josephg l33t
Joined: 10 Jan 2016 Posts: 783 Location: usually offline
|
Posted: Sat Feb 17, 2018 1:01 am Post subject: |
|
|
hence why i wanna try script something to suspend (a child process) if loadavg>x
there are other things running too, which drive up loadavg. |
|
Back to top |
|
|
frostschutz Advocate
Joined: 22 Feb 2005 Posts: 2977 Location: Germany
|
Posted: Sat Feb 17, 2018 1:28 am Post subject: |
|
|
use kill to send stop, cont signals to child process?
Code: |
$ date; (sleep 10 && date) &
Sat Feb 17 02:25:25 CET 2018
$ pid=$!
$ kill -SIGSTOP $pid
[1]+ Stopped ( sleep 10 && date )
$ kill -SIGCONT $pid
Sat Feb 17 02:28:01 CET 2018
[1]+ Done ( sleep 10 && date )
|
|
|
Back to top |
|
|
josephg l33t
Joined: 10 Jan 2016 Posts: 783 Location: usually offline
|
Posted: Sat Feb 17, 2018 1:39 am Post subject: |
|
|
thank you frostschutz. exactly what i was looking for. now i can try loop those kills in my script to try tame resource intensive process(es).
i wouldn't have looked for this in kill of all the places. where/how could i list all the kill SIGs? i couldn't find in manpages.
update: kill -l lists all signals |
|
Back to top |
|
|
|