如何从C中的apache CGI进程中分离独立的PHP进程?

Basically I have a CGI module written in C and I want to detach a totally independent PHP process. The PHP process has no relation to the CGI other than that the latter passes a parameter to the former via the command line. Once the detach occurs, the two process have nothing further to do with each other and complete asynchronously. Both access the database independently and perform unrelated functions. The original process does not wait for the detached process and does not care whether or not it finishes, successful or otherwise. Both processes terminate after performing their specific functions. The detached process sets file paths explicitly, so the default directory of the original process is not relevant.

Suppose that the command to start is "php.exe arg1 arg2".

Under Windows you can use the function CreateProcess to create a detached process in you cgi:

STARTUPINFO si;
PROCESS_INFORMATION pi;

memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
if (!CreateProcess(NULL, // name of executable module
        "php.exe ag1 arg2", // command line string
        NULL, // SD
        NULL, // SD
        FALSE, // handle inheritance option
        CREATE_NEW_CONSOLE, // creation flags
        NULL, // new environment block
        NULL, // current directory name
        &si, // startup information
        &pi // process information))
{
    logError();
}

Under Linux or other Unix like OS, you can use the function fork in coordination with execvp:

int pid = fork();
if (pid < 0)
{
    logError();
}
else if (pid == 0) // Child Process
{
    char *args[] = { "php.exe", "arg1, "arg2", NULL };
    exevp(args[0], args);
    logError(); // should never reach this line
}