The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


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
Question about defunct processes EMCSANMAN UNIX for Dummies Questions & Answers 1 02-08-2008 10:03 AM
defunct process on HP shriashishpatil UNIX for Advanced & Expert Users 1 12-08-2006 06:08 AM
defunct process!! rish2005 High Level Programming 5 11-30-2005 11:47 AM
defunct process due to scohttp on SCO5.0.5 npn35 SCO 0 05-26-2005 07:22 AM
<DEFUNCT> Processes cuppjr UNIX for Dummies Questions & Answers 4 02-26-2001 03:55 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 04-03-2007
Registered User
 

Join Date: Apr 2007
Posts: 17
Angry Defunct Process Problem

Hi!
I'm newbi in the Unix. I've a C++ Program from where one shell gets executed. Sample C++ code is --

transactionID = 1199;

case 1199:
//*************************************************
// Received the suspend signal.
//*************************************************
//Call monitoring script, to check proper end of maintstaticloader
if (fork() == 0)
{
execlp("monTx1199.sh", "monTx1199.sh", (char *)0);
exit(0);
}

Name of the C++ program is - MAINRCVR.cpp.

And, in the shell i've the following code --

PROCESS=${BINDIR}/DRCVR/MAINTRCVR

---------------
Some more process
---------------

maintrcvr_pid=`ps -ef | grep -v grep | grep "${PROCESS}" | awk '{print $2}'`
kill -s SIGCONT $maintrcvr_pid

-But, Even if i kill this process - it is still showing defunct table. We have done test runs of this and it seems to run fine, but all of a sudden after some days of running i see that there are almost 1000 of defunct processes. I've tried --

kill -9 $maintrcvr_pid

But, nothing happen. Pls give me some suggestion in this regard. Thanks in advance.

Satyaki De.
Reply With Quote
Forum Sponsor
  #2  
Old 04-04-2007
Registered User
 

Join Date: Mar 2007
Posts: 3
Forking twice to avoid zombies.

May try the following

if (fork() == 0) //Child of the main code
{
if (fork()> 0) //Another process is created.(Grandchild)
exit(0); //1st child(ret val of fork >0) exits making the Grandchild orphan so it will not be zombie.
execlp("monTx1199.sh", "monTx1199.sh", (char *)0);
//Above line is executed in the grand child whose status will be retrieved by init.

}
wait(&status) ; // In the main code where status is an int variable.
//or waitpid function to wait for a specific child.
//that means we need not wait for the Grandchild to complete , which will run the shell script.

Refer Stevens (Advanced Programming in the Unix environment , Process Control Chapter)

Last edited by tb75; 04-04-2007 at 04:48 AM.
Reply With Quote
  #3  
Old 04-04-2007
Registered User
 

Join Date: Apr 2007
Posts: 17
Hi!
Thanks for your reply.

Regards.

Satyaki De.

Quote:
Originally Posted by tb75
May try the following

if (fork() == 0) //Child of the main code
{
if (fork()> 0) //Another process is created.(Grandchild)
exit(0); //1st child(ret val of fork >0) exits making the Grandchild orphan so it will not be zombie.
execlp("monTx1199.sh", "monTx1199.sh", (char *)0);
//Above line is executed in the grand child whose status will be retrieved by init.

}
wait(&status) ; // In the main code where status is an int variable.
//or waitpid function to wait for a specific child.
//that means we need not wait for the Grandchild to complete , which will run the shell script.

Refer Stevens (Advanced Programming in the Unix environment , Process Control Chapter)
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:28 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0