Child process is not getting started


 
Thread Tools Search this Thread
Top Forums Programming Child process is not getting started
# 1  
Old 09-16-2006
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);
	}

..pls help me out...its bit urgent Smilie

Last edited by reborg; 09-16-2006 at 04:50 PM..
# 2  
Old 09-16-2006
please use code tags ... Smilie Smilie

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 !!!
# 3  
Old 09-16-2006
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 Smilie Smilie
# 4  
Old 09-17-2006
i doubt here
Code:
printf("---in child");

since the buffer is not filled with just '---in child'
and the printf is not directed to flush immediately
i think it is delayed...

try as

Code:
printf("---in child\n");

# 5  
Old 09-17-2006
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
# 6  
Old 09-17-2006
thanx alot...

by using printf("--in child\n") instead of printf("--in child") , i got the desired output
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

I need to save a pid of a child started with $: su <user> -c “nohup …”

Hello, I want to save pid of a child process but I get empty file. su myuser -c "nohup ./mydaemon.sh >/dev/null 2>&1 & print $! > mydaemon.pid" This one works: nohup ./mydaemon.sh >/dev/null 2>&1 & print $! > mydaemon.pid Please help. Thank you in advance. (2 Replies)
Discussion started by: vincegata
2 Replies

2. Shell Programming and Scripting

how to check whether a process started at particular time

I want to check whether a particular process has started at 10:00a.m or not. I can check process by ps -fu but dont know how to check it with respect to time. Could anyone help me with this? ---------- Post updated at 11:14 AM ---------- Previous update was at 10:52 AM ---------- can i use... (9 Replies)
Discussion started by: kishore kumar
9 Replies

3. Shell Programming and Scripting

forking a child process and kill its parent to show that child process has init() as its parent

Hi everyone i am very new to linux , working on bash shell. I am trying to solve the given problem 1. Create a process and then create children using fork 2. Check the Status of the application for successful running. 3. Kill all the process(threads) except parent and first child... (2 Replies)
Discussion started by: vizz_k
2 Replies

4. Emergency UNIX and Linux Support

signal between parent process and child process

Hello, everyone. Here's a program: pid_t pid = fork(); if (0 == pid) // child process { execvp ...; } I send a signal (such as SIGINT) to the parent process, the child process receive the signal as well as the parent process. However I don't want to child process to receive the... (7 Replies)
Discussion started by: jackliang
7 Replies

5. Red Hat

Killing child daemon started by parent process

Hi All, Hope this is right area to ask this question. I have a shell script (bash) "wrapper.sh", which contains few simple shell command which executes a "server.sh" (conatins code to execute a java server) as a daemon. Now what I want to kill this "server.sh" so that the server should... (2 Replies)
Discussion started by: jw_amp
2 Replies

6. Shell Programming and Scripting

[KSH/Bash] Starting a parent process from a child process?

Hey all, I need to launch a script from within 2 other scripts that can run independently of the two parent scripts... Im having a hard time doing this, if anyone knows how please let me know. More detail. ScriptA (bash), ScriptB (ksh), ScriptC (bash) ScriptA, launches ScriptB ScirptB,... (7 Replies)
Discussion started by: trey85stang
7 Replies

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

8. Shell Programming and Scripting

Process id of the exe started with nohup

Hi, I have a strange problem. In my shell script, i am startting another program (a c++ exe) with nohup . I am getting the process id of this started process with using $! I am writing this process id into another file so that i can keep checking for this process ids to check whether the... (2 Replies)
Discussion started by: parvathi_rd
2 Replies

9. UNIX for Advanced & Expert Users

how to know that a perticular process is started!!!

Hi all, I wanted a write a script which will start executing whenever a particular process will starts running in a background. Is there is any way in Unix if a directory contents changed then a signal/Interrupt will generated and by taking status of that interrupt I can execute some scripts.... (11 Replies)
Discussion started by: zing_foru
11 Replies

10. UNIX for Dummies Questions & Answers

Process started on console

Please can someone describe what causes undesired process startup on system console. ps -ef output is like: root 1763 1 0 16:22:24 console 0:00 /bin/sh /usr/System........ process is blocking system console for any access (2 Replies)
Discussion started by: zverzak
2 Replies
Login or Register to Ask a Question