![]() |
![]()
| ![]() |
![]()
NAME
SYNOPSIS#include <agar/core.h> DESCRIPTIONThe
INTERFACEAG_ProcessID
The function returns the PID of the terminated process, -1 if an
error has occurred, or 0 if wait_type is
The
EXAMPLESThe following code runs a program on a Unix-like system: char *argv[3]; AG_ProcessID pid; argv[0] = "ls"; argv[1] = "-l" argv[2] = (char *)NULL; pid = AG_Execute("/bin/ls", argv); if (pid == -1) AG_Verbose("Execute failed (%s)\n", AG_GetError()); The following code launches a background task on Windows and terminates its execution after 10 seconds: char *argv[2]; AG_ProcessID pid; int counter = 0; argv[0] = "MyTask"; argv[1] = (char *)NULL; pid = AG_Execute("C:\Program Files\" "Example\MyTask.exe"); for (;;) { if (AG_WaitOnProcess(pid, AG_EXEC_WAIT_IMMEDIATE) == -1) { AG_Verbose("Task exited unexpectedly (%s)\n", AG_GetError()); break; } if (counter++ == 10) { if (AG_Kill(pid) == -1) { AG_Verbose("Kill failed (%s)\n", AG_GetError()); } break; } sleep(1); } SEE ALSOHISTORYThe
|