Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
shell script suspend/resume child processes
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
josephg
l33t
l33t


Joined: 10 Jan 2016
Posts: 783
Location: usually offline

PostPosted: Fri Feb 16, 2018 1:59 pm    Post subject: shell script suspend/resume child processes Reply with quote

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
View user's profile Send private message
Naib
Watchman
Watchman


Joined: 21 May 2004
Posts: 6051
Location: Removed by Neddy

PostPosted: Fri Feb 16, 2018 2:18 pm    Post subject: Reply with quote

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
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3342
Location: Rasi, Finland

PostPosted: Fri Feb 16, 2018 2:35 pm    Post subject: Reply with quote

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
View user's profile Send private message
josephg
l33t
l33t


Joined: 10 Jan 2016
Posts: 783
Location: usually offline

PostPosted: Fri Feb 16, 2018 10:36 pm    Post subject: Reply with quote

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
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21622

PostPosted: Sat Feb 17, 2018 12:26 am    Post subject: Reply with quote

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
View user's profile Send private message
josephg
l33t
l33t


Joined: 10 Jan 2016
Posts: 783
Location: usually offline

PostPosted: Sat Feb 17, 2018 1:01 am    Post subject: Reply with quote

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
View user's profile Send private message
frostschutz
Advocate
Advocate


Joined: 22 Feb 2005
Posts: 2977
Location: Germany

PostPosted: Sat Feb 17, 2018 1:28 am    Post subject: Reply with quote

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
View user's profile Send private message
josephg
l33t
l33t


Joined: 10 Jan 2016
Posts: 783
Location: usually offline

PostPosted: Sat Feb 17, 2018 1:39 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum