Find the answer to your Linux question:
Results 1 to 3 of 3
Code: if(count > 1){ //fork() printf("START OF WHILE - %i \n", count); int cid = fork(); count--; printf("1st: %i \n", count); if(cid == 0){ //Child process printf("%i \n", cid); execvp(cmdTokens[0], ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2012
    Posts
    19

    fork/execvp


    Code:
    if(count > 1){ //fork()
    			printf("START OF WHILE - %i \n", count);
    				int cid = fork();
    				count--;
    				printf("1st: %i \n", count);
    				if(cid == 0){ //Child process
    					printf("%i \n", cid);
    					execvp(cmdTokens[0], cmdTokens);
    				} else if(cid > 0){ //Parent process
    					waitpid(cid, 0, 0);
    					printf("%i \n", cid);
    					execvp(cmdTokens[0], cmdTokens);
    				}
    				printf("END OF LOOP \n");
    			printf("END OF WHILE - %i \n", count);
    		}
    For some reason, my code only gets to the else if statement and does not go to the "printf("END OF LOOP \n");" Does anyone know why this might be?

  2. #2
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    From the man page of execve:
    Code:
    DESCRIPTION
           The exec family of functions shall replace the current process image with a new process image. The new image shall be constructed from a regular, executable file called the  new  process
           image file. There shall be no return from a successful exec, because the calling process image is overlaid by the new process image.
    The exec family of functions never returns.

  3. #3
    Just Joined!
    Join Date
    Sep 2012
    Posts
    19
    Quote Originally Posted by Cabhan View Post
    From the man page of execve:
    Code:
    DESCRIPTION
           The exec family of functions shall replace the current process image with a new process image. The new image shall be constructed from a regular, executable file called the  new  process
           image file. There shall be no return from a successful exec, because the calling process image is overlaid by the new process image.
    The exec family of functions never returns.
    Hmm... that helped a bit. Let me test a few things out and see what happens.

  4. $spacer_open
    $spacer_close

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •