fork question

John E. Davis davis at pacific.mps.ohio-state.edu
Thu Feb 7 06:24:53 AEST 1991


Hi,

   I have a program, called `sline' with the front end:

   main()
{  
    char *position,*init_status,*exit_status,*terminal;
    int matched;
    int child_pid, parent_pid, parent;
    FILE *fpstatus;

    
    parent_pid = getppid();
    
    /* we create an identical process to do the work and exit the parent */
    /* now fork off a child to do all of the work */
    switch (child_pid = fork())
	{
	  case 0:
	    /* this is the child; let it go on */
	    break;
	  case -1:
	    /* oops... something wrong! */
	    perror("sline");
	    exit(1);
	    break;
	  default:
	    /* the parent... may exit after sending the pid of the child */
	    printf("%d\n",child_pid);
	    exit(0);
	}

[....]

As you can see, the program forks with the parent exiting returning the pid of
the child process.  This is precisely what happens when I run it at the unix
command line.  Now in my .login I have the line:
       .
       .
set slinepid = `sline`
       .
       .


which sets the variable `slinepid' to the pid of the child.  This variable
gets set but my .login gets hung up here-- ie. it does not continue beyond
this point; I have to ^C to kill it.

What fundamental point am I missing here?  It seems to me that the .login is
waiting for the child to exit as well.

Thanks,
--
John

  bitnet: davis at ohstpy
internet: davis at pacific.mps.ohio-state.edu



More information about the Comp.unix.questions mailing list