Execute a function in background and then suspend it

Here is some back ground on the script. The script is to poll an arbitrary number of DB's. To do this I am creating a function that takes the file_path to the DB and the min poll interval as arguments. The function will be called for each DB and then ran in the background. The function I was originally planning on creating would be in a while true loop and I would be able to kill -stop or kill -cont each instance of the function at will. I am unable to obtain the PID of the functions. I can see that they are there when I use the command top and I can kill each individual occurrence of the function. This proves it is possible but I am looking to do this in the script containing the function. So as to eliminate user input. This is my first post, so I am unsure if I have provided the necessary information. If not feel free to ask any additional questions. I am also not entirely sure I am approaching this problem the correct way. So if you have any alternative routes I would be interested in hearing.

I don't think this will be a reliable way to control the subshell. It can still be woken by other things like SIGCHLD which you have no control over.

I don't know why you'd even want to, anyway -- why run something only to immediately halt it? Why not run it when you actually want it to run, no sooner?

1 Like

What is the method for this "poll"? What is it for?

I poll recent changes by identifiers. So when someone updates something the script knows.

---------- Post updated at 09:01 AM ---------- Previous update was at 08:58 AM ----------

How many times I execute the function is dependent on how many DB's there are. So I figured I would begin executing the functions in a loop. such as

for i in #DB
do
function_name &
done

Each database would also have its own min poll time. This means I can not execute all functions at the same time. Does this make sense?

So you can run some of them at the same time but not all of them?

How does your script determine which ones can and which ones can't?

Not being familiar with your particular database, I don't understand what you mean by "min poll".

It appears I found an answer to the problem. Thank you Corona688 I found my answer when exploring the possibility of just using the function when I need to. For some reason when thinking originally I assumed that would be impossible without user input.

1 Like

Please post the solution - it might help explain the question.