![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Can a child process return a specific value to a parent process ? | Ametis1970 | High Level Programming | 8 | 04-09-2008 11:22 PM |
| how to know that a perticular process is started!!! | zing_foru | UNIX for Advanced & Expert Users | 11 | 05-19-2007 10:04 AM |
| Process started on console | zverzak | UNIX for Dummies Questions & Answers | 2 | 12-07-2006 04:33 AM |
| is there any way to know how much time process was running from the moment it started | umen | UNIX for Dummies Questions & Answers | 2 | 04-03-2006 12:19 AM |
| PID of process started in background?? | stilllooking | Shell Programming and Scripting | 2 | 11-16-2004 03:47 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Child process is not getting started
Hi,
When i m trying to run below code,its entering into wait stage. output: In parent pid=2134 // some random value assigned to child process parent waiting..... and then it keeps on waiting for child to get terminate Y this child is not getting started....atleast i should get " ---in child" Code:
printf("In parent");
for(i=0;i<3;i++)
{
pid=fork();
printf("pid= %d",pid);
if(pid==0)
{
printf("---in child");
memset(temp,0,100);
strcpy(temp,commandList[i]);
intial_command=strtok(temp," ,\0,");
if(i==0)
{
close(1);
dup2(pipes[0][0],1);
close(pipes[0][1]);
execvp(intial_command,commandList[i]);
}
else
{
if(i==countCommands-1)
{
close(0);
dup2(pipes[i][1],0);
close(pipes[i][0]);
execvp(intial_command,commandList[i]);
}
else
{
close(0);
dup2(pipes[i][1],0);
close(1);
dup2(pipes[i][0],1);
execvp(intial_command,commandList[i]);
}
}
}
printf("parent waiting.....");
waitpid(pid,&processStatus,0);
}
![]() Last edited by reborg; 09-16-2006 at 03:50 PM.. |
|
||||
|
please use code tags ...
you are checking only with pid == 0 what if the system (kernel) has failed to fork a process ? check the condition if pid < 0 also check from ps -ef that both parent and child are running !!! |
|
||||
|
Both parent and child processes are running....still its not goiing into child's code
i tried to check which all processes are running....actaully both child and parent processes are running...but its not entering into child's code
![]() |
|
||||
|
i doubt here
Code:
printf("---in child");
and the printf is not directed to flush immediately i think it is delayed... try as Code:
printf("---in child\n");
|
|
||||
|
You really need to check the return from your fork, like for instance:
fork_return = fork(); if( fork_return < 0) { curtime = time (NULL); /* get current time */ loctime = localtime (&curtime); fprintf(fplog,"Unable to spawn child process, exiting. "); fputs (asctime (loctime), fplog); fprintf(fplog, "errno: %s\n",strerror(errno)); exit(-1); } Add in errno.h and then look at the errno string. Good luck, Jen |
|
||||
|
thanx alot...
by using printf("--in child\n") instead of printf("--in child") , i got the desired output
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|