Thread: Fork() not working.

  1. #1
    Registered User
    Join Date
    Apr 2006

    Fork() not working.

    I'm trying to get fork() working but I keep getting the error message fork undefined. I've copied and pasted this code straight from the FAQ section. I'm using Bloodshed C++. Ideas?

    #include <stdio.h> 
    #include <stdlib.h> 
    #include <sys/types.h>
    #include <unistd.h> 
    int main(void)
      char *my_args[5];
      pid_t pid;
      my_args[0] = "child.exe";
      my_args[1] = "arg1";
      my_args[2] = "arg2";
      my_args[3] = NULL;
      puts ("fork()ing");
      switch ((pid = fork()))
        case -1:
          /* Fork() has failed */
          perror ("fork");
        case 0:
          /* This is processed by the child */
          execv ("child.exe", my_args);
          puts("Uh oh! If this prints, execv() must have failed");
          /* This is processed by the parent */
          puts ("This is a message from the parent");
      puts ("End of parent program");
      return 0;
     * Program output:
     This is a message from the parent
     End of parent program
     I am the child
     Arg 1 arg1
     Arg 2 arg2

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    United States
    <unistd.h> and <sys/types.h> are UNIX headers, which Bloodshed isn't going to port to windows any time soon. Likewise I don't think you can use anything that depends on <process.h> either but I'm not so sure on that.

    Use one of the Windows API options maybe?

  3. #3
    </3 Segfaults
    Join Date
    Jul 2007
    Bloodshed made a compiler?

  4. #4
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    No, an IDE.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fork in windows os
    By cnu_sree in forum C Programming
    Replies: 3
    Last Post: 01-12-2008, 04:02 AM
  2. Fork(), pause(), and storing PID's in a linked list
    By vital101 in forum C Programming
    Replies: 10
    Last Post: 09-28-2007, 02:16 AM
  3. Fork - unpredictable?
    By fredkwok in forum Linux Programming
    Replies: 4
    Last Post: 03-26-2006, 01:49 PM
  4. fork(), exit() - few questions!
    By s3t3c in forum C Programming
    Replies: 10
    Last Post: 11-30-2004, 05:58 AM
  5. problems with fork() and execve()
    By kristy in forum C Programming
    Replies: 4
    Last Post: 12-21-2003, 07:18 AM
Website Security Test