System Calls

Alarm(s) : RngIntElt ->
A procedure which when used on UNIX systems, sends the signal SIGALRM to the Magma process after s seconds. This allows the user to specify that a Magma-process should self-destruct after a certain period.
ChangeDirectory(s) : MonStgElt ->
Change to the directory specified by the string s. Tilde expansion is allowed.
GetCurrentDirectory() : ->
Returns the current directory as a string.
Getpid() : ->
Returns Magma's process ID (value of the Unix C system call getpid()).
Getuid() : ->
Returns the user ID (value of the Unix C system call getuid()).
System(C) : MonStgElt -> RngIntElt
Execute the system command specified by the string C. This is done by calling the C function system().

This also returns the system command's return value as an integer. On most Unix systems, the lower 8 bits of this value give the process status while the next 8 bits give the value given by the command to the C function exit() (see the Unix manual entries for system(3) or wait(2), for example). Thus one should normally divide the result by 256 to get the exit value of the program on success.

See also the Pipe intrinsic function.

Example IO_GetDate (H3E19)

The System intrinsic can be used to access the current date and time.
> System("date");
Tue Feb 28 13:02:03 EST 2017
%! shell-command
Execute the given command in the Unix shell then return to Magma. Note that this type of shell escape (contrary to the one using a System call) takes place entirely outside Magma and does not show up in Magma's history.
V2.28, 13 July 2023