Execute a function in background and then suspend it


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execute a function in background and then suspend it
# 1  
Old 06-22-2012
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.
# 2  
Old 06-22-2012
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?
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 06-22-2012
Quote:
The script is to poll an arbitrary number of DB's.
What is the method for this "poll"? What is it for?
# 4  
Old 06-22-2012
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 ----------

Quote:
Originally Posted by Corona688
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?
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?
# 5  
Old 06-22-2012
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".
# 6  
Old 06-22-2012
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.
This User Gave Thanks to ryandavison For This Post:
# 7  
Old 06-22-2012
Quote:
I poll recent changes by identifiers. So when someone updates something the script knows.
Please post the solution - it might help explain the question.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

While loop hangs in function running in background

Hello Everyone, I am writing a shell script to fetch log files from remote servers within a time range. It copies log files to local server, grep for date and then compares the time stamp of each log entry with the once specified. Below is the code. # Get log and Parsing function ... (1 Reply)
Discussion started by: kanagalamurali
1 Replies

2. Shell Programming and Scripting

how do i execute nohup and background job inside the korn script for db2

load_cursor_stmt() { ls /db/admin/ddl/rmn01000/load_cursor*.sql|while read file do echo "${file}" `nohup db2 -tvf "$file" \&` done }Error: ------- /admin/ddl/rmn01000/load_cursor5.sql /db/admin/ddl/rmn01000/load_cursor6.sql + read file + echo... (3 Replies)
Discussion started by: Hangman2
3 Replies

3. Shell Programming and Scripting

Using ssh to execute a remote script in the background

Help please!! I want to use ssh to execute a remote exe and while it's running I want to query for the process ID of the exe (2 different ssh commands) 1. sshpass -p "<passwd>" ssh -f -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@<ipaddress> nohup /tmp/mmds_asyn & 2.... (0 Replies)
Discussion started by: rvompoluTMW
0 Replies

4. Shell Programming and Scripting

A puzzle with a printing function executing in background

Somebody on a thread in the (french) Mandriva Forum recently suggested a script, designed to provide a tool to display kind of "temporisation widgets" on the console (to be ultimately pasted in other more complex scripts). One version of this script was something like the following, which seems... (6 Replies)
Discussion started by: klease
6 Replies

5. UNIX for Dummies Questions & Answers

suspend a *background* running job

Is there a way to suspend (TSTP?) a job that is running in the background, _without_ first bringing it to the foreground and inputting Ctrl-Z from the keyboard? IOW, something similar to issuing the shell's bg builtin command on a job ID to resume a job that is suspended in the background,... (2 Replies)
Discussion started by: uiop44
2 Replies

6. Shell Programming and Scripting

A question about the PID of a background function

Dear all, I'm writing a KornShell script that calls inside it a function in background mode #!/bin/ksh function myfunction { . . .} myfunction |& . . . How can I capture the PID of the function myfunction that runs in background? Thanks in advance :) (2 Replies)
Discussion started by: dariyoosh
2 Replies

7. Shell Programming and Scripting

unable to execute background job

I am unable to execute the below command in background. Plz suggest. #> ./test input >out & 913618 + Stopped (SIGTTIN) ./test input >out & Suresh (1 Reply)
Discussion started by: suresh3566
1 Replies

8. Programming

want to run a function in background

consider the given prg. main() { ..... function1(); /* to write into a file or log */ printf(" "); ..... } when the control reaches function1(), it should get executed in the background.At the same time main's printf(" ") statement should also get executed.i.e... (5 Replies)
Discussion started by: bankpro
5 Replies

9. UNIX for Dummies Questions & Answers

subshell & background function

Hello all, Can someone explain to me the advantage between using subshell over a function call in scripts? To me these are the same. Am I wrong to think this? (4 Replies)
Discussion started by: larry
4 Replies
Login or Register to Ask a Question