Standard interview question, and actually, many variations on the answer. First, classic wait for specific job:
You can also wait for all jobs with a barefoot wait. Check man ksh. When running a bare wait from the command line, be aware that it waits for other, unrelated jobs you ran from that terminal shell.
Also beware, the child processes will be done, but their descendents may still be running!
More sophisticated, and capable of monitoring all descendent processes:
When every process inside the parentheses closes (or redirects) both stdout and stderr, the cat will end. You can use stdout for payload or logging, but generally, to keep the parent waiting, reserve one of the two for logging. Plus, you have an integrated log, always a nice idea.
You can also run fuser on the log files to see if any pid has it open. Of course, if someone has their vi nose in there, you will think it is still being written unless you check the pids with ps -fp $pid.
Re: jobs: Only if it is interactive -- no shell script can do this unless it has an expect layer or other source of tty. Even then, you get jobs of other tasks also in the background on this tty, like with wait. Just from memory, I think running on the command line in a subshell ( ; wait) allows you to avoid waiting for unrelated processes.
You are right. This allows you to test without blocking, too. Like wait on the command line, you get all the background. If you subshell or are scripting, you are free of them -- Other People's Children OPC. Of course, their children may still be running! The inheritied stdout/err (...)| cat can track the deeper children.
---------- Post updated at 02:25 PM ---------- Previous update was at 02:25 PM ----------
Hello again,
I am runnning a job on a cluster and I submit a job with the command
qsub script.sh
where script.sh is a script with the command i want o use. When i enter this command the cluster gives a huber like 123456 as the JOB ID.
I want the job to run about 12 hours and when it... (5 Replies)
Hi,
I am using net::ftp for transferring files now i am trying in the same Linux server as a result ftp is very fast but if the server is other location (remote) then the file transferred will be time consuming.
So i want try putting FTP part as a background process. I am unaware how to do... (5 Replies)
Hello,
I am running GNU bash, version 3.2.39(1)-release (x86_64-pc-linux-gnu). I have a specific question pertaining to waiting on jobs run in sub-shells, based on the max number of parallel processes I want to allow, and then wait... (1 Reply)
Hello, I know this isn't exactly a Unix question, but I wasn't able to find much information elsewhere.
I'm trying to run a program in the background using Cygwin on a Windows machine, then use the wait command to pause before proceeding. Unfortunately, as I've confirmed using ps aux, the... (0 Replies)
What I need to learn is how to use a script that launches background processes, and then kills those processes as needed.
The script successfully launches the script. But how do I check to see if the job exists before I kill it?
I know my problem is mostly failure to understand parameter... (4 Replies)
Hi,
I'm trying to write a script to decompress a directory full of files. The decompression commands can run in the background, so that many can run at once. But I want to limit the number running at any one time, so that I don't overload the machine.
Something like this:
n=0
for i in *.gz... (15 Replies)
Hello,
I am a novice shell script programmer. And facing this problem any help is appreciated.
I m writing a shell script and running few commands in it background as I have to run them simultaneously.
Sample code :
sql_prog &
sql_prog &
sql_prog &
echo "Process Completed"
Here... (2 Replies)
Hi all,
I am trying to find out the process wait time on Unix(AIX/SOLARIS) machine( only sh/ksh/csh):
Like
EXAMPLE 1 :
$ vmstat 2
System configuration: lcpu=16 mem=32000MB
kthr memory page faults cpu
----- -----------... (4 Replies)
Hello Experts!!
My CPU is waiting a lot (around 33%) on I/O. I would like to find out what process(s) are waiting on the i/o. Below is my real time output of vmstat and sar.
Thanks for you help !!!!
Regards
Citrus
OS: AIX - 5L
: /u2/oracle >oslevel
5.3.0.0
: /u2/oracle... (9 Replies)
how to know the information of the waiting process
how to calculate the time of the process that it has taken to execute
i want to make a program that Should be able to keep a log of the processes expired(The log should contain the starting time, expiry time, time slices used, total execution... (2 Replies)