|
| iMatix home page | << | < | > | >> |
SFLVersion 2.11 |
#include "sflproc.h"
int
process_status (
PROCESS process)
Returns status of process specified by process ID. Returns one of these values, or -1 if there was an error:
| PROCESS RUNNING | Process is still running. |
| PROCESS ENDED OK | Process ended normally. |
| PROCESS ENDED ERROR | Process ended with an error status. |
| PROCESS INTERRUPTED | Process was interrupted (killed). |
{
#if (defined (__UNIX__) || defined (__OS2__))
int
status;
pid_t
return_pid;
/* waitpid() returns 0 if the child process is still running, or the */
/* process id if it stopped. It can also return -1 in case of error. */
/* No other return value is possible. */
return_pid = waitpid (process, &status, WNOHANG | WUNTRACED);
if (return_pid == 0)
return (PROCESS_RUNNING);
else
if (return_pid == process)
{
if (WIFEXITED (status)) /* Program called exit() */
{
process_errno = WEXITSTATUS (status);
if (process_errno) /* Treat exit (0) as normal end */
return (PROCESS_ENDED_ERROR);
else
return (PROCESS_ENDED_OK);
}
else
if (WIFSIGNALED (status)) /* Process was interrupted */
return (PROCESS_INTERRUPTED);
else
return (PROCESS_ENDED_OK);
}
else
return (-1);
#elif (defined (WIN32))
DWORD
status;
ASSERT (process);
status = WaitForSingleObject (process-> process, 0);
if (status == WAIT_TIMEOUT)
return (PROCESS_RUNNING);
else
if (status == WAIT_OBJECT_0)
return (PROCESS_ENDED_OK);
else
if (status == WAIT_ABANDONED)
return (PROCESS_ENDED_ERROR);
else
return (-1);
#elif (defined (__VMS__))
ASSERT (process);
if (process-> status == 0)
return (PROCESS_RUNNING);
else
return (PROCESS_ENDED_OK);
#else
return (-1); /* Not supported on this system */
#endif
}
| | << | < | > | >> |
|