Sponsored Content
Operating Systems Linux Red Hat Fork wait in background process - large delay Post 302328041 by vishnu.priya on Tuesday 23rd of June 2009 08:24:40 AM
Old 06-23-2009
Fork wait in background process - large delay

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 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
Code:
    switch ( pid = fork())
    {
        case -1:
            DbgMsg( DBG_ERR, "Cannot fork for compile!\n");
            single--;
            return -1;
        case 0:
            execvp( file, argv);
            DbgMsg(DBG_ERR | DBG_COMPILER, "Should never happen\n");
        default:
            {
waitloop:
            died = wait(&status);
            if (died == pid)
                break;
            if (died == -1) {
#if 0 /* on systems that don't map errno to __error() */
                extern int errno;
#endif

                DbgMsg(DBG_WARNING | DBG_COMPILER, "Compilation error (%s)\n", strerror(errno));
                switch (errno) {
                    case ECHILD:
                    case EINTR:
                        break;
                    default:
                        DbgMsg( DBG_WARNING, "Unexpected compilation error (%d)\n", errno);
                        goto waitloop;
                }
            }
            DbgMsg( DBG_WARNING, "Wait returned for other child %x\n", died);
            goto waitloop;
            }
    }

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...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Wait for Background Process to complete

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)
Discussion started by: gozer13
3 Replies

2. Shell Programming and Scripting

wait command - cat it wait for not-chile process?

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)
Discussion started by: alex_5161
2 Replies

3. UNIX for Advanced & Expert Users

how to make a parent wait on a child shells running in background?

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)
Discussion started by: albertashish
1 Replies

4. Shell Programming and Scripting

wait in background

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)
Discussion started by: albertashish
1 Replies

5. UNIX for Dummies Questions & Answers

How can i use fork,sleep,wait and write in a process with father and son..??

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)
Discussion started by: gumlucin
3 Replies

6. Red Hat

Fork wait in background process - large delay

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)
Discussion started by: vishnu.priya
1 Replies

7. Shell Programming and Scripting

How to make the parent process to wait for the child process

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)
Discussion started by: sennidurai
7 Replies

8. Programming

Newbie question on exec,fork, wait,pipe C

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)
Discussion started by: Cuervo
1 Replies

9. Shell Programming and Scripting

calling a shell script in background and wait using "wait" in while loop

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)
Discussion started by: mihirvora16
2 Replies

10. Programming

Linux fork, execv, wait question

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
EXIT(2) 							System Calls Manual							   EXIT(2)

NAME
_exit - terminate a process SYNOPSIS
_exit(status) int status; DESCRIPTION
_exit terminates a process with the following consequences: All of the descriptors open in the calling process are closed. This may entail delays, for example, waiting for output to drain; a process in this state may not be killed, as it is already dying. If the parent process of the calling process is executing a wait or is interested in the SIGCHLD signal, then it is notified of the calling process's termination and the low-order eight bits of status are made available to it; see wait(2). The parent process ID of all of the calling process's existing child processes are also set to 1. This means that the initialization process (see intro(2)) inherits each of these processes as well. Any stopped children are restarted with a hangup signal (SIGHUP). Most C programs call the library routine exit(3), which performs cleanup actions in the standard I/O library before calling _exit. RETURN VALUE
This call never returns. SEE ALSO
fork(2), sigvec(2), wait(2), exit(3) 4th Berkeley Distribution May 22, 1986 EXIT(2)
All times are GMT -4. The time now is 08:45 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy