Allows to creates a new process executable or a child process which executes a function.
Process | Allows to creates a new process executable or a child process which executes a function. |
Copyright | This program is free software. |
Files | |
C-kern/ | Header file of Process. |
C-kern/ | Implementation file Process Linuximpl. |
Types | |
struct process_t | Make process_t an alias of sys_process_t. |
process_task_f | Defines function type executed by process_t. |
struct process_result_t | Export process_result_t into global namespace. |
struct process_stdio_t | Export process_stdio_t into global namespace. |
Enumerations | |
process_state_e | Describes the state of a process. |
Functions | |
test | |
unittest_platform_task_process | Unittest for pagecache module. |
process_result_t | Holds result of terminated process. |
Variables | |
returncode | Either the exit number or signal number. |
state | Either process_state_TERMINATED or process_state_ABORTED. |
process_stdio_t | The process standard io channel redirections. |
lifetime | |
process_stdio_INIT_DEVNULL | Static initializer lets new process write and read from null device. |
process_stdio_INIT_INHERIT | Static initializer lets new process inherit standard io channels. |
update | |
redirectin_processstdio | Redirects standard input to given file. |
redirectout_processstdio | Redirects standard output to given file. |
redirecterr_processstdio | Redirects standard error output to given file. |
process_t | Represents system specific process. |
lifetime | |
process_FREE | Static initializer. |
init_process | Creates child process which executes a function. |
initgeneric_process | Same as init_process except that it accepts functions with generic argument type. |
initexec_process | Executes another program with same environment. |
free_process | Frees resource associated with a process. |
query | |
name_process | Returns the system name of the calling process in the provided buffer. |
state_process | Returns current state of process. |
change | |
daemonize_process | Prepares this process to be a daemon process. |
wait_process | Waits until process has terminated. |
inline implementation | |
process_stdio_t | |
redirectin_processstdio | Implements process_stdio_t.redirectin_processstdio. |
redirectout_processstdio | Implements process_stdio_t.redirectout_processstdio. |
redirecterr_processstdio | Implements process_stdio_t.redirecterr_processstdio. |
process_t | |
initgeneric_process | Implements process_t.initgeneric_process. |
This program is free software. You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
© 2011 Jörg Seebohn
Header file of Process.
Implementation file Process Linuximpl.
Make process_t an alias of sys_process_t.
typedef int ( * process_task_f ) (void * task_arg)
Defines function type executed by process_t.
typedef struct process_result_t process_result_t
Export process_result_t into global namespace.
typedef struct process_stdio_t process_stdio_t
Export process_stdio_t into global namespace.
Describes the state of a process.
test | |
unittest_platform_task_process | Unittest for pagecache module. |
struct process_result_t
Holds result of terminated process.
Variables | |
returncode | Either the exit number or signal number. |
state | Either process_state_TERMINATED or process_state_ABORTED. |
struct process_stdio_t
The process standard io channel redirections. The process standard input, output and error channel are redirected to the files given in this structure. Redirection means that instead of reading from standard input the process reads from <process_stdio_t.infile>. And instead of writing to standard output or standard error it writes to <process_stdio_t.outfile> resp. <process_stdio_t.errfile>.
Make sure that redirected files are automatically closed in case another process is executed (i.e. have set their O_CLOEXEC flag).
lifetime | |
process_stdio_INIT_DEVNULL | Static initializer lets new process write and read from null device. |
process_stdio_INIT_INHERIT | Static initializer lets new process inherit standard io channels. |
update | |
redirectin_processstdio | Redirects standard input to given file. |
redirectout_processstdio | Redirects standard output to given file. |
redirecterr_processstdio | Redirects standard error output to given file. |
void redirectin_processstdio( process_stdio_t * stdfd, sys_iochannel_t input_file )
Redirects standard input to given file. Use value <iochannel_FREE> to redirect standard input to device null. Use value iochannel_STDIN to let child inherit standard error.
void redirectout_processstdio( process_stdio_t * stdfd, sys_iochannel_t output_file )
Redirects standard output to given file. Use value <iochannel_FREE> to redirect standard output to device null. Use value iochannel_STDOUT to let child inherit standard error.
void redirecterr_processstdio( process_stdio_t * stdfd, sys_iochannel_t error_file )
Redirects standard error output to given file. Use value <iochannel_FREE> to redirect standard error to device null. Use value iochannel_STDERR to let child inherit standard error.
typedef sys_process_t process_t
Represents system specific process.
lifetime | |
process_FREE | Static initializer. |
init_process | Creates child process which executes a function. |
initgeneric_process | Same as init_process except that it accepts functions with generic argument type. |
initexec_process | Executes another program with same environment. |
free_process | Frees resource associated with a process. |
query | |
name_process | Returns the system name of the calling process in the provided buffer. |
state_process | Returns current state of process. |
change | |
daemonize_process | Prepares this process to be a daemon process. |
wait_process | Waits until process has terminated. |
int init_process( /*out*/process_t * process, process_task_f child_main, void * start_arg, process_stdio_t * stdfd )
Creates child process which executes a function. Setting pointer stdfd to 0 has the same effect as providing a pointer to process_stdio_t initialized with <process_stdio_INIT_DEVNULL>.
int initgeneric_process( /*out*/process_t * process, process_task_f child_main, void * start_arg, process_stdio_t * stdfd )
Same as init_process except that it accepts functions with generic argument type. The argument must have same size as sizeof(void*).
int initexec_process( /*out*/process_t * process, const char * filename, const char * const * arguments, process_stdio_t * stdfd /*0 = > /dev/null*/ )
Executes another program with same environment. The parameter “filename” specifies the path to an executeable binary. If it does not contain any “/” the program is searched for in the search path specified with the PATH environment variable. The parameter “arguments” is an array of pointers to C-strings that represent the argument list available to the new program. The first argument should point to the filename associated with the file being executed. It must be terminated by a NULL pointer.
int free_process( process_t * process )
Frees resource associated with a process. If a process is running it is killed. So call wait_process before to ensure the process has finished properly. ECHILD is returned if process does no longer exist.
int name_process( size_t namebuffer_size, /*out*/char name[namebuffer_size], /*out*/size_t * name_size )
Returns the system name of the calling process in the provided buffer. The returned string is always null-terminated even if the provided buffer is smaller then the name.
namebuffer_size | The size in bytes of the name buffer. If namebuffer_size is smaller than the size of the process name the returned value is truncated. A value of 0 means nothing is returned. |
name | The name of the process is returned in this buffer. The last character is always a ‘\0’ byte. Points to character buffer of size namebuffer_size. |
name_size | Is set to the size of the name including the trailing \0 byte. If this pointer is NULL nothing is returned. |
int daemonize_process( process_stdio_t * stdfd/*0 = > /dev/null*/ )
Prepares this process to be a daemon process. The working directory is set to ‘/’, umask is set to S_IRWXO, the process becomes the session leader and all 3 stdio channels are redirected to /dev/null. This call works only if there are no other running threads besides the calling thread. The reason is that after return only the calling thread is running and all other threads have no chance to free their resources. After return the process id has been changed.
#define redirectin_processstdio( stdfd, input_file ) ((void)((stdfd)->std_in = input_file))
Implements process_stdio_t.redirectin_processstdio.
#define redirectout_processstdio( stdfd, output_file ) ((void)((stdfd)->std_out = output_file))
Implements process_stdio_t.redirectout_processstdio.
#define redirecterr_processstdio( stdfd, error_file ) ((void)((stdfd)->std_err = error_file))
Implements process_stdio_t.redirecterr_processstdio.
#define initgeneric_process( process, child_main, start_arg, stdfd ) ( __extension__ ({ int (*_child_main) (typeof(start_arg)) ; _child_main = (child_main) ; static_assert( sizeof(start_arg) == sizeof(void*), "same as void*" ) ; init_process( process, (process_task_f) _child_main, (void*)start_arg, stdfd ) ; }))
Implements process_t.initgeneric_process.
Represents system specific process.
typedef sys_process_t process_t
Chooses Posix process id.
#define sys_process_t pid_t
Defines function type executed by process_t.
typedef int ( * process_task_f ) (void * task_arg)
Export process_result_t into global namespace.
typedef struct process_result_t process_result_t
Holds result of terminated process.
struct process_result_t
Export process_stdio_t into global namespace.
typedef struct process_stdio_t process_stdio_t
The process standard io channel redirections.
struct process_stdio_t
Unittest for pagecache module.
int unittest_platform_task_process( void )
Either the exit number or signal number.
int returncode
Either process_state_TERMINATED or process_state_ABORTED.
process_state_e state
Static initializer lets new process write and read from null device.
#define process_stdio_INIT_DEVNULL { sys_iochannel_FREE, sys_iochannel_FREE, sys_iochannel_FREE }
Static initializer lets new process inherit standard io channels.
#define process_stdio_INIT_INHERIT { sys_iochannel_STDIN, sys_iochannel_STDOUT, sys_iochannel_STDERR }
Redirects standard input to given file.
void redirectin_processstdio( process_stdio_t * stdfd, sys_iochannel_t input_file )
Redirects standard output to given file.
void redirectout_processstdio( process_stdio_t * stdfd, sys_iochannel_t output_file )
Redirects standard error output to given file.
void redirecterr_processstdio( process_stdio_t * stdfd, sys_iochannel_t error_file )
Static initializer.
#define process_FREE sys_process_FREE
Creates child process which executes a function.
int init_process( /*out*/process_t * process, process_task_f child_main, void * start_arg, process_stdio_t * stdfd )
Same as init_process except that it accepts functions with generic argument type.
int initgeneric_process( /*out*/process_t * process, process_task_f child_main, void * start_arg, process_stdio_t * stdfd )
Executes another program with same environment.
int initexec_process( /*out*/process_t * process, const char * filename, const char * const * arguments, process_stdio_t * stdfd /*0 = > /dev/null*/ )
Frees resource associated with a process.
int free_process( process_t * process )
Returns the system name of the calling process in the provided buffer.
int name_process( size_t namebuffer_size, /*out*/char name[namebuffer_size], /*out*/size_t * name_size )
Returns current state of process.
int state_process( process_t * process, /*out*/process_state_e * current_state )
Prepares this process to be a daemon process.
int daemonize_process( process_stdio_t * stdfd/*0 = > /dev/null*/ )
Waits until process has terminated.
int wait_process( process_t * process, /*out*/process_result_t * result )
Implements process_stdio_t.redirectin_processstdio.
#define redirectin_processstdio( stdfd, input_file ) ((void)((stdfd)->std_in = input_file))
Implements process_stdio_t.redirectout_processstdio.
#define redirectout_processstdio( stdfd, output_file ) ((void)((stdfd)->std_out = output_file))
Implements process_stdio_t.redirecterr_processstdio.
#define redirecterr_processstdio( stdfd, error_file ) ((void)((stdfd)->std_err = error_file))
Implements process_t.initgeneric_process.
#define initgeneric_process( process, child_main, start_arg, stdfd ) ( __extension__ ({ int (*_child_main) (typeof(start_arg)) ; _child_main = (child_main) ; static_assert( sizeof(start_arg) == sizeof(void*), "same as void*" ) ; init_process( process, (process_task_f) _child_main, (void*)start_arg, stdfd ) ; }))