can i use fork() and getpid() functions in a console application in windows XP to creat child process if yes then why the following code is not working.If no,then how should i create a child process.
#include<sys/types.h>
#include<iostream>
usingnamespace std;
int main()
{
int pid,ppid,cpid;
cout<<"Main Process with pid : "<<getpid();
cout<<"\nSplit starts : ";
pid=fork();
if(pid==0)
{
cout<<"\nChild Process with pid :"<<getpid();
}
else
{
cout<<"\nParent Process with pid :"<<getpid();
}
}
I think Win32 does provide _getpid(), although GetCurrentProcessId is a better option.
The bigger issue here is the *nix and Windows handle creating new threads/processes in different philosophical ways, and simply taking a Unix way and translating it directly to Windows functions isn't the best option. You'd be better off learning the Win32 way of creating new processes/threads.