aotto

Hi,

I have a problem to check for process availability in a CRT based application.

I'm using:

pid = _spawnlp (_P_NOWAIT, cmd, buf->data, NULL)

to start a background process and need help to check if the initialisation

of the process fails.

_spawnlp allready return an error if something happen during startup like cmd is missing

but i want to wait for ~ 0.1 sec and just check for the pid still exists. the problem is that

_cwait is blocking until the process is finished. under unix I'm using:

waitpid (pid, NULL, WNOHANG)

with:

WNOHANG The waitpid() function will not suspend exe-
cution of the calling process if status is
not immediately available for one of the
child processes specified by pid.

how can I check I the process still exists with only the pid as argument

-> thanks for help

mfg

Andreas Otto




Re: Visual C++ General check for process availability using process-id

Viorel.

If no other solutions, you could try the following approach:

Code Snippet

if( ::WaitForSingleObject((HANDLE)pid, 100) == WAIT_TIMEOUT)

{

// the process is still running during 0.1 sec.

. . .

}

or

Code Snippet

if( ::WaitForSingleObject((HANDLE)pid, 0) == WAIT_TIMEOUT)

{

// the process is still running right now.

. . .

}

I hope this helps.





Re: Visual C++ General check for process availability using process-id

Simple Samples

Process id is not useful for doing that. You are mixing C code with code specific to Unix/Linux and you seem to expect that Unix/Linux works the same as Windows.

I don't know how your program manages process, but there are probably many useful items in the Windows documentation. Probably there are a few books that include explanation of threads and synchronization.