execution in background

hey

im having trouble understanding how to execute commands in the background. i did some research and saw that you only have to fork and not wait for the child to finish. in another case you have to change the process group. i ve really tried both of them but i just cant get them to work. so i anyone feels like helping out, id appreciate it a lot. thanks

heres what i got so far.

a->background is set to 1 if one of the arguments on the command line equals '&'.


 /* create a process space */

      if ((pid = fork()) < 0) {

        perror ("Fork failed");
        exit(errno);
      }

      if (!pid) { // pid == 0

	printf(" \n if (!pid) = %d ", pid);

        printf (" child process[%d]\n", getpid ()); /* Display child PID */
        /* Child process */

	if (a->background == 1) {

// so when it comes across a '&', 

      	   if (fork () == 0) {

	     // just fork(); do not wait for the child
	     signal (SIGQUIT, originalQuitHandler); /* Oldhandler */
             setpgid (0, getpid ()); /* Change process group */
             execvp(a->com_name, a->argv);
	   }
	}

	else {

           /* This is the child, so execute the ls */ 
           execvp (a->com_name, a->argv);
	}
      }

      if (pid) {

	printf(" \n if (pid) = %d ", pid);
        
         /* We're in the parent; let's wait for the child to finish */
        waitpid (pid, NULL, 0);
      }
      	
	return;

thanks again

mile 1982 8O