Fork wait in background process - large delay

 
Thread Tools Search this Thread
Operating Systems Linux Red Hat Fork wait in background process - large delay
# 1  
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 jim mcnamara; 06-23-2009 at 04:22 PM.. Reason: add code tags
# 2  
Old 06-25-2009
Bumping up posts or double posting is not permitted in these forums.

Please read the rules, which you agreed to when you registered, if you have not already done so.

You may receive an infraction for this. If so, don't worry, just try to follow the rules more carefully. The infraction will expire in the near future

Thank You.

The UNIX and Linux Forums.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
Login or Register to Ask a Question