We are trying to run a process in the background and in the process we call fork ;and wait for the child process to finish .We find that the died = wait(&status); happens after 10 seconds randomly and sometimes completes in time (within 1 sec)
This behavior is seen only when the program is run as a background process. With foreground the functionality is always within 1 sec.
Can anyone please suggest the reason for this random scheduling in Linux - Operating system is CentOS
Thanks in advance for any help
Thanks
Vishnu
Last edited by vbe; 06-23-2009 at 12:15 PM..
Reason: added code tag + rm fancy URL...
I am attempting within a for-loop, to have my shell script (Solaris v8 ksh) wait until a copy file command to complete before continueing. The specific code is:
for files in $(<inputfile.lst)
do
mv directory/$files directory/$files
ksh -m -i bg %%
wait $!
done
I am shaky on the... (3 Replies)
Did not use 'wait' yet.
How I understand by now the wait works only for child processes, started background.
Is there any other way to watch completion of any, not related process (at least, a process, owned by the same user?)
I need to start a background process, witch will be waiting... (2 Replies)
Hi
I have a shell script A which calls another 10 shell scripts which run in background. How do i make the parent script wait for the child scripts complete, or in other words, i must be able to do a grep of parent script to find out if the child scripts are still running.
My Code:
... (1 Reply)
can a wait command be run in background? or the script which has the wait command, be run background?
test.sh
-------
nohup a.sh &
nohup b.sh &
wait
nohup test.sh &
How can i run either wait or test.sh in background? i want test.sh to wait till a.sh and b.sh complete, and must be... (1 Reply)
Hi..
I was unable to do (gcc code) which refers to the fork,wait,sleep and write..
what i want to do:
A process of father create (fork) a son and will sleep 90 seconds..After this, son process create a grandchild and will sleep 60 seconds..Grandchild process will sleep for 30 seconds..After... (3 Replies)
hi all,
We are trying to run a process in the background and in the process we call fork ;and wait for the child process to finish .We find that the died = wait(&status); happens after 10 seconds randomly and sometimes completes in time (within 1 sec)
This behavior is seen only when the... (1 Reply)
Hi All,
I have two ksh script. 1st script calls the 2nd script and the second script calls an 'C' program.
I want 1st script to wait until the 'C' program completes.
I cant able to get the process id for the 'C' program (child process) to make the 1st script to wait for the second... (7 Replies)
Hello everybody.I want to make clear that i am not going to ask from anybody to build my asignement but i have a big problem. I can't seem to find anywhere ONE good example on C about what i am trying to do:wall:.I think it is simple. All i ask is one example, even a link is fine.
So, i want to... (1 Reply)
Hi,
I am facing a strange issue,
when i call a script from my while loop in background it doesnt go in background, despite the wait i put below the whil loop it goes forward even before the process put in background is completed.
cat abc.txt | while read -u4 line
do
#if line contains #... (2 Replies)
Hi All,
I have a program for class that needs to do the following:
1. Print the directory entries from the current directory using ncurses
2. Provide a prompt next to each directory entry and allow the user to enter commands that may or may not be about the file
3. Execute those commands in... (1 Reply)
Discussion started by: afulldevnull
1 Replies
LEARN ABOUT MINIX
wait
WAIT(2) System Calls Manual WAIT(2)NAME
wait, waitpid - wait for process to terminate
SYNOPSIS
#include <sys/types.h>
#include <sys/wait.h>
pid_t wait(int *status)
pid_t waitpid(pid_t pid, int *status, int options)
DESCRIPTION
Wait causes its caller to delay until a signal is received or one of its child processes terminates. If any child has died since the last
wait, return is immediate, returning the process id and exit status of one of the terminated children. If there are no children, return is
immediate with the value -1 returned.
On return from a successful wait call, status is nonzero, and the high byte of status contains the low byte of the argument to exit sup-
plied by the child process; the low byte of status contains the termination status of the process. A more precise definition of the status
word is given in <sys/wait.h>. If wait can called with a null pointer argument to indicate that no status need be returned.
Waitpid provides an alternate interface for programs that must not block when collecting the status of child processes, or that wish to
wait for one particular child. The pid parameter is the process ID of the child to wait for, -1 for any child. The status parameter is
defined as above. The options parameter is used to indicate the call should not block if there are no processes that wish to report status
(WNOHANG), and/or that children of the current process that are stopped due to a SIGTTIN, SIGTTOU, SIGTSTP, or SIGSTOP signal should also
have their status reported (WUNTRACED). (Job control is not implemented for Minix, but these symbold and signals are.)
When the WNOHANG option is specified and no processes wish to report status, waitpid returns -1 with errno set to EAGAIN. The WNOHANG and
WUNTRACED options may be combined by or'ing the two values.
NOTES
The call wait(&status) is equivalent to waitpid(-1, &status, 0).
See sigaction(2) for a list of termination statuses (signals); 0 status indicates normal termination. A special status (0177) is returned
for a stopped process that has not terminated and can be restarted; see ptrace(2). If the 0200 bit of the termination status is set, a
core image of the process was produced by the system.
If the parent process terminates without waiting on its children, the initialization process (process ID = 1) inherits the children.
<sys/wait.h> defines a number of macros that operate on a status word:
WIFEXITED(status)
True if normal exit.
WEXITSTATUS(status)
Exit status if the process returned by a normal exit, zero otherwise.
WTERMSIG(status)
Signal number if the process died by a signal, zero otherwise.
WIFSIGNALED(status)
True if the process died by a signal.
WIFSTOPPED(status)
True if the process is stopped. (Never true under Minix.)
WSTOPSIG(status)
Signal number of the signal that stopped the process.
RETURN VALUE
If wait returns due to a stopped or terminated child process, the process ID of the child is returned to the calling process. Otherwise, a
value of -1 is returned and errno is set to indicate the error.
Waitpid returns -1 if there are no children not previously waited for, if the process that it wants to wait for doesn't exist, or if WNO-
HANG is specified and there are no stopped or exited children.
ERRORS
Wait will fail and return immediately if one or more of the following are true:
[ECHILD] The calling process has no existing unwaited-for child processes.
[EFAULT] The status argument points to an illegal address.
[EAGAIN] Waitpid is called with the WNOHANG option and no child has exited yet.
SEE ALSO execve(2), exit(2), sigaction(2).
4th Berkeley Distribution June 30, 1985 WAIT(2)