Probably, some snippet of Golang code that does such thing (in probably unobvious way) could help me. Or better the reference to some 3rd party golang library that gives wide control over child processes (CPU priority, oom_score_adj, etc.)
Asked
Active
Viewed 74 times
1
-
You cannot exec a process directly into a stopped state (and definitely not in a cross platform way). On unix systems you could immediately send `SIGSTOP` after starting the process. – JimB Apr 10 '23 at 18:36
-
Yes, I saw a Linux-specific post about a bash stub script that calls kill and exec for that purpose. Can I do a similar thing in Golang (without calling bash)? Also, how can I create a suspended process in Golang when running on Windows that indeed supports that (but does not support exec) – Roman Maltsev Apr 11 '23 at 09:06
-
Yes, you can immediately send a `SIGSTOP` after starting the process without using bash. Windows does not have an equivalent, but maybe read [here](https://stackoverflow.com/questions/11010165/how-to-suspend-resume-a-process-in-windows/11010508) (remember that Go processes are always multithreaded). This all seems like an XY problem though. _Why_ do you think you need to try and pause a process in the first place? Any process settings should be setup before starting the process. – JimB Apr 11 '23 at 12:36
-
I want to tune priority, oom_score_adj and other parameters before a demanding child process actually start working and competing with the supervisor (parent) for resources. I also need to know process pid in advance, so that when a process starts to interact with the supervisor, its pid is already known at that moment. – Roman Maltsev Apr 11 '23 at 13:14
-
You can't know the PID of a process in advance. Any process controls should be set up before starting the process, not after the process has executed some arbitrary amount of code. If you are going to change settings on a running process, just change the settings, pausing for those few microseconds is not going to be any safer, and if it makes a difference you already have a race condition – JimB Apr 11 '23 at 14:38
-
I don't know a beautiful way to tune all these parameters using standard os/exec interface. Old-school way would be to start process paused, tune all its parameters, learn its pid and finally send SIGCONT. Actually, there is a flag for that in clone() that could have been passed in os/exec, but its support was removed from a kernel. Of course I could modify os/exec code to do my things between fork and exec, but I'd like to avoid it. – Roman Maltsev Apr 12 '23 at 10:05