Help with fork()

Hi, I'm wanting to do some stuff with fork(), but I ran into some problems.

Here's my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
using namespace std;

int main()
{
	pid_t pid;
	int x = 0;
	bool f = false;

	pid = fork();
}


And when I build it I get "'fork' was not declared in this scope" as an error.

Can someone please tell me why this is happening?
You didn't include stdlib.h
I thought fork() was defined in unistd.h
¿Is that the only error that you are getting?
It is defined in <unistd.h>
What compiler and OS are you using?
@h9uest
I added stdlib.h just in case, that didn't fix the problem (same error).

@ne555
Yes that is my only error. I purposefully kept my program small to reduce errors so I could single out what it was. :P

@Duoas
I suppose I am using GCC C++ Compilier. I am using Windows 7.

I say suppose, because I'm not 100% sure if that's what my program is using. I downloaded Eclipse and MinGW. I am writing the code in Eclipse and use MinGW GCC as a toolchain for my project.
You can't use fork() with MinGW, as it is a POSIX function, but not a Windows API function.

There are alternatives. You can compile using the Cygwin environment, which provides a full POSIX platform at the cost of a runtime DLL. You can use a Linux OS, either as a separate bootable partition on your PC, or in a Virtual Machine environment (obligatory link http://www.lifehack.org/articles/technology/beginners-guide-run-linux-like-any-other-program-in-windows.html ), or you can hack your own fork() function from undocumented NT system calls, or you can simply use the Windows API directly (obligatory link http://www.google.com/search?btnI=1&q=msdn+Porting+from+UNIX+to+Win32 ).

Hope this helps.
Indeed. Thanks for letting me know.

It's too bad that what I was using doesn't support what I want, though, heh. I do have a linux computer here so I'll just get on it and use that. I just don't like having to switch monitors and stuff all the time, lol.

Again, I appreciate your help.
Topic archived. No new replies allowed.