GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
AG_EXECUTE(3) FreeBSD Library Functions Manual AG_EXECUTE(3)

AG_Executeagar file execution interface

#include <agar/core.h>

The () function provides a cross-platform interface for running executable programs and monitoring their execution.

AG_ProcessID
AG_Execute(const char *file, char **argv);


AG_ProcessID
(AG_ProcessID pid, enum ag_exec_wait_type wait_type);


int
(AG_ProcessID pid);

() runs the specified program with the given arguments, returning an integer process ID. If an error has occurred, the function returns -1 with an error message.

() checks for status or waits until the specified process terminates. The wait_type argument may be one of:

AG_EXEC_WAIT_IMMEDIATE
If the process has not exited, return immediately without blocking.
AG_EXEC_WAIT_INFINITE
Block the calling thread until the process has exited.

The function returns the PID of the terminated process, -1 if an error has occurred, or 0 if wait_type is AG_EXEC_WAIT_IMMEDIATE and the process is still running.

The () function immediately terminates the specified process.

The 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);
}

AG_Intro(3)

The AG_Execute interface first appeared in Agar 1.4.1.

December 21, 2022 Agar 1.7

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.