GRASS 8 Programmer's Manual 8.6.0dev(2026)-b0a6d7703c
Loading...
Searching...
No Matches
spawn.c File Reference

GIS Library - Handles process spawning. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <stdarg.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <grass/config.h>
#include <grass/gis.h>
#include <grass/glocale.h>
#include <grass/spawn.h>
Include dependency graph for spawn.c:

Go to the source code of this file.

Macros

#define MAX_ARGS   256
 
#define MAX_BINDINGS   256
 
#define MAX_SIGNALS   32
 
#define MAX_REDIRECTS   32
 
#define NEXT_ARG(var, type)   ((type) * (var)++)
 
#define NEXT_ARG_INT(var)   (int)((intptr_t)*(var)++)
 

Functions

int G_vspawn_ex (const char *command, const char **args)
 Spawn new process based on command.
 
int G_spawn_ex (const char *command,...)
 Spawn new process based on command.
 
int G_spawn (const char *command,...)
 Spawn new process based on command.
 
int G_wait (int i_pid)
 Wait for a spawned process to finish.
 

Detailed Description

GIS Library - Handles process spawning.

SPDX-FileCopyrightText: 2001-2014 GRASS Development Team SPDX-License-Identifier: GPL-2.0-or-later

Author
Glynn Clements
Date
2004-2006

Definition in file spawn.c.

Macro Definition Documentation

◆ MAX_ARGS

#define MAX_ARGS   256

Definition at line 41 of file spawn.c.

◆ MAX_BINDINGS

#define MAX_BINDINGS   256

Definition at line 42 of file spawn.c.

◆ MAX_REDIRECTS

#define MAX_REDIRECTS   32

Definition at line 44 of file spawn.c.

◆ MAX_SIGNALS

#define MAX_SIGNALS   32

Definition at line 43 of file spawn.c.

◆ NEXT_ARG

#define NEXT_ARG (   var,
  type 
)    ((type) * (var)++)

Definition at line 730 of file spawn.c.

◆ NEXT_ARG_INT

#define NEXT_ARG_INT (   var)    (int)((intptr_t)*(var)++)

Definition at line 731 of file spawn.c.

Function Documentation

◆ G_spawn()

int G_spawn ( const char command,
  ... 
)

Spawn new process based on command.

Parameters
[in]command
Returns
-1 on error
process status on success

Definition at line 918 of file spawn.c.

References G_spawn_ex(), MAX_ARGS, NULL, SF_ARGVEC, SF_SIGNAL, SSA_BLOCK, SSA_IGNORE, and SST_PRE.

◆ G_spawn_ex()

int G_spawn_ex ( const char command,
  ... 
)

Spawn new process based on command.

This is a more advanced version of G_spawn().

Parameters
[in]command
Returns
-1 on error
process status on success

Definition at line 897 of file spawn.c.

Referenced by D_open_driver(), db_start_driver(), and G_spawn().

◆ G_vspawn_ex()

int G_vspawn_ex ( const char command,
const char **  args 
)

Spawn new process based on command.

This is a more advanced version of G_spawn().

Parameters
[in]command
[in]argsarguments
Returns
-1 on error
process status on success

Definition at line 877 of file spawn.c.

◆ G_wait()

int G_wait ( int  i_pid)

Wait for a spawned process to finish.

Blocks until the process identified by i_pid exits, then returns the process exit code. On non-Windows platforms, if the process terminates due to a signal, the signal number is returned instead.

Parameters
[in]i_pidProcess identifier returned by a spawn function.
Returns
Process exit code on normal termination.
Signal number if the process was terminated by a signal on non-Windows platforms.
-1 if the process cannot be opened, waited for, or queried.
-0x100 (-256) if the process ended with an unsupported wait status on non-Windows platforms.

Definition at line 963 of file spawn.c.

References FALSE.

Referenced by db_shutdown_driver(), and G_popen_close().