NO

Author Topic: fork() problem  (Read 4159 times)

31si

  • Guest
fork() problem
« on: May 27, 2009, 05:48:13 pm »
I have a small problem at the moment. I am writing an program which parses some information from a file but I want to fork the program. I am using pelles but it will not allow me to use this command.
Here is an example program which uses fork. I have tried compiling this but it doesn't work. I know that this code works because I have compiled it with gcc and it executes perfectly on linux.

Code: [Select]
#include  <stdio.h>
#include  <string.h>
#include  <sys/types.h>

#define   MAX_COUNT  200
#define   BUF_SIZE   100

void  main(void)
{
     pid_t  pid;
     int    i;
     char   buf[BUF_SIZE];

     fork();
     pid = getpid();
     for (i = 1; i <= MAX_COUNT; i++) {
          sprintf(buf, "This line is from pid %d, value = %d\n", pid, i);
          write(1, buf, strlen(buf));
     }
}

Any Idea how I can get this to work with windows?

Here is the error that I get

- - - - - - - - - - Yag.exe - - - - - - - - - -
Building Yag.exe.
POLINK: error: Unresolved external symbol '_fork'.
POLINK: fatal error: 1 unresolved external(s).
*** Error code: 1 ***
Done.
« Last Edit: May 27, 2009, 05:56:17 pm by 31si »

JohnF

  • Guest
Re: fork() problem
« Reply #1 on: May 27, 2009, 05:57:50 pm »
fork() is not part of the C run time or Windows API's.

Have you looked up the Windows API CreateProcess()?

Here is a link to the MSDN library page that describes CreateProcess()

http://msdn.microsoft.com/en-us/library/ms682425.aspx

John

31si

  • Guest
Re: fork() problem
« Reply #2 on: May 27, 2009, 06:01:20 pm »
Thank you.... that does appear to cover it. However I feel that I will just write my app for unix. I like the idea better that you can just call fork and it does it. Instead of having to pass a shed load of arguments to it.

Thank you John [bows]

aj

  • Guest
Re: fork() problem
« Reply #3 on: June 02, 2009, 12:27:03 am »
Use threads instead for these kind of things. They are more lightweight and doesn't require a potential copy of the whole process address space.

It's quite easy to write code that works with both pthreads and Win32 threads.