
Terminating a child process
Quote:
> Hi all,
> I am currently developing a C program on AIX 4.0 that
interacts with a
> proprietary communication protocol server. The program
involves
> establishing sessions, receiving data and writing data to
Oracle
> database.
> I am forking a child process to write the data to the
database. The
> problem I face is that the forked child processes do not
terminate after
> the function is executed. But once the parent terminates, all
the child
> processes terminates.
> The attached code is a copy of the mechanism used in the
actual code.
> Can anyone tell me why the child processes do not terminate ?
> Code begins here :
> #include <stdio.h>
> #include <signal.h>
> #include <sys/errno.h>
> #include <unistd.h>
> int main()
> {
> int i=0;
> pid_t pid;
> while (1)
> {
> if (i==10)
> exit(0);
> pid = fork();
> if (pid == 0)
> {
> print_val();
> exit(0);
> }
> i++;
> sleep(3);
> }
> }
> int print_val()
> {
> int i,j;
> for (i=0;i<10;i++)
> {
> j=j+i;
> printf("Value is : %d\n",j);
> }
> return 0;
> }
> Code Ends here.
> Thanks for your help,
> Sajid.
Hi Sajid,
Nope, if you ask the question here, read the answer here.
This question is off topic for comp.lang.c, which discusses the
standard C programming language and not specific operating
system issues. The header file uistd.h is not part of standard
C, neither is pid_t, fork, or sleep. These are specific to UNIX
and UNIX like operating systems.
I would suggest you post this question to comp.unix.aix, or a
one of the comp.unix.* groups.
Please read the article "--- Welcome to comp.lang.c! Please
read this first" which is posted frequently to this group by
Billy Chambless so that in the future you will know what
subjects are on and off topic here.
Jack