Thread: Child process are running for infinite time

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    134

    Child process are running for infinite time

    I have used fork() to memory share programming.
    The child process are running for infinite time even I am unable to stop it by pressing ctrl+c on linux.
    How can I stop it using ctr+c
    or there are any other method?
    Do I need to remember something when I am working with fork to tackle such irritating situations?

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    In the short term, you should be able to kill the processes by finding their process IDs (with "ps aux | grep program", for example) and then using "kill -KILL" to send a SIGKILL signal to the processes.

    To solve the real problem you should make sure you don't have any deadlock conditions. Can you post some of your code, or the output of a run of the program, or anything else that gives more detail as to what the problem is?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    134
    Code:
    main(int argc, char *argv[])
    {
    
    	if(fork()==0)	{						
    
    		if(fork()==0)	{
    		
    			while(*dED == 0 && time!=10)	{	
    				}	
    				sleep(1);
    				time++;
    			}
    			system("");
    		}
    		else{			
    			
    			while(TRUE)	{		
    	                                        }
    	else	{
    		while(TRUE)	{
    			
    			}
      			sleep(1);
      			time++;
    		}
    	}
    
    }

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    You should keep the PID from the fork() call, if you intend infanticide.

    Code:
    pid_t p = fork();
    if ( p == 0 ) {
      // do some stuff
    } else {
      sleep(3);
      kill(p, SIGINT );
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 05-01-2011, 11:06 AM
  2. Replies: 2
    Last Post: 03-16-2010, 07:15 PM
  3. parent child process
    By simo_mon in forum C Programming
    Replies: 2
    Last Post: 08-03-2008, 03:44 AM
  4. Child Process & Parent Process Data :: Win32
    By kuphryn in forum Windows Programming
    Replies: 5
    Last Post: 09-11-2002, 12:19 PM
  5. I apologize. Good bye.
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 05-03-2002, 06:51 PM