Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using fork and execlp under 10.20 HP-UX, odd shell problem...

Status
Not open for further replies.

programgo

Programmer
Jun 8, 2001
4
0
0
US
Hello Programmers:
I hope that some one out there has run into this problem and knows how to solve it.
On one of my systems which is an L Class HP server running HP-UX 10.20
I have a C program that does a fork() and execlp() call to start a couple of other
C programs, and then the parent program goes on about its business while the child
processes(programs) are running on their own.
The problem I get is this, the programs start up OK meaning that the fork() and
execlp() calls are working just fine. The two C programs start up OK with no problems
but then what I get is (when a ps -ef is done) I see this type of output
where sh -c has been executed and now a duplicate (or what appears to be) a second
copy of the program is now running.
This is being envoked in a /sbin/sh (posix) environment running as root, via sudo.

Further what is odd is that on most of the other systems that are running 11.0
this programming all works perfectly with no problem at all.

Also when I had called execl instead of execlp then just one copy of the program was
running again with the sh -c command as though the exec call thought for some
reason that the call was a call to a shell script and not a C binary.

The real main problem that this causes is that when the sh -c call is made and
the child program is running, it causes the parent program to wait which is what I
DON'T want it to do. I want the child processes to be spawned off and no waiting
and allow the parent process to continue on.

I do not call wait or waitpid inside the parent process so this should not be happening.

I hope this makes sense, as it is a bit difficult to explain.

Hope someone out there knows what is going on with the program.
I can give code examples if necessary.

Thanks.
 
If the parent process is completed before the child process is completed then it will cause problem. The child may go on running [ ie the child process will not be kill automatically ].

what i understood form your explanation ...

You don't want the parent process to wait for the child process to complete and you want to execute both the process simultaneously.

Yes you can do like that but before the completion of the parent process put a wait(NULL) function call [ This will not affect the flow of the parent process because at the end of parent process only you are going call wait() ].

Make a child process. Let them on their way but before the completion of the parent process put the wait(NULL).

Maniraja S
 
In this situation I use C standard
system(CommandLine);
function.
To start it in Background mode use & at the end of execution name on UNIX. To pass some data to starting programm I use shared memory. Works fine on HP,SUN,SGI (Nt too but with call to CreateProcess())
Regards.
 
well, in the code for the child process, give an exit() at the last line. That should help.
 
if you don't wan't the parent to wait for the child to finish, you would have to use spawnl(P_NOWAIT, etc..) and then explicitly kill the parent (if that's what you want done)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top