1

im new to C++ and it was hard for me to find a good IDE. Now i have Code Blocks, but i cant use the Systemcalls like fork, wait etc.

I use Windows 7.

#include <iostream>
#include <stdlib.h>;
#include <sys/types.h>
#include <unistd.h>

using namespace std;

int main()
{

    cout << "I am " << (int) getpid() << endl;
    pid_t pid = fork();
    cout << "fork returned" << (int) pid << endl;
        return 0;

        if(pid<0) {
            cout << "Failed !" << endl;
            exit(3);
        }
        if(pid == 0) {
                cout << "i am the child" << (int) getpid() << endl;
                cout << "Child exiting" << endl;
                exit(0);

        }

        if(pid >= 0) {
            cout << "i am the parent" << (int) getpid() << endl;
            wait(NULL);
            cout << "Parent ending" << endl;
        }

        return 0;
}

I cant include sys/wait.h Errors :

error : fork was not declared in this scope error : wait was not declared in this scope

Thanks in advice !

Raccoon20
  • 35
  • 5

1 Answers1

3

I use Windows 7.

Then indeed you are going to struggle using POSIX functions. Windows is not a POSIX OS.

You will need to use the Windows API's functions instead.

Take your list of project requirements, then research how to achieve each of them in Windows.

For example:

Community
  • 1
  • 1
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055