Howdy all!
I have an application that creates and interacts with sockets and some low-level devices. I currently pass it a config file so it knows what kind of environment it runs in. What I would like to do is run one instance of this application for each device all at the same time, something like:
# program configfile1 &
# program configfile2 &
etc., so they're all running at the same time.
However whenever I do that, none of the sockets are created and it seems the program does nothing. There's no user interaction here, although it speaks to the serial port. If I wait and hit enter at the prompt, I get:
Stopped [45] program
where 45 is its pid.
I think I can do something like this in the main(...) of my application:
and this will do what I want.Code:if ((pid = vfork()) < 0) { perror("Error in vfork()"); return; } //end if vfork error //child else if (pid == 0) { //we are the child sigignore(SIGINT); //ignore keyboard interrupts close(STDIN_FILENO); //close stdin printf("[%d] %ld\n", numOfBackgrounds, getpid()); //print ACK .... put all the rest of my code here........ } //end if } else //parent { if (!background) waitpid(pid, NULL, 0); //wait for child since we're foreground }
However I am still curious as to why a non-user-interactive program won't create sockets when executed in the background?
This is on RH 8.0 using the bash shell.
Thanks.
Curious.



LinkBack URL
About LinkBacks




I could understand if the serial settings were executed by the parent before it died, so it died before resetting the port settings, but they're not, my parent returns(1) before it ever gets a chance to mess with the serial port settings.