Process Linuximpl

Implements Process.

Summary
Process LinuximplImplements Process.
CopyrightThis program is free software.
Files
C-kern/api/platform/task/process.hHeader file of Process.
C-kern/platform/Linux/task/process.cImplementation file Process Linuximpl.
process_stdfd2_t
lifetime
init_processstdio2Initializes process_stdfd2_t with process_stdio_t and opens devnull.
free_processstdio2Closes if devnull if necessary.
redirectstdfd_processstdio2Redirects one standard channel to read/write from/to a file.
redirectstdio_processstdio2Redirects all 3 standard io channels to read/write from/to a file.
process_t
helper
lifetime
fork_processThis function call returns twice.
query
change
test

Copyright

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.

Author

© 2011 Jörg Seebohn

Files

C-kern/api/platform/task/process.h

Header file of Process.

C-kern/platform/Linux/task/process.c

Implementation file Process Linuximpl.

process_stdfd2_t

Summary
lifetime
init_processstdio2Initializes process_stdfd2_t with process_stdio_t and opens devnull.
free_processstdio2Closes if devnull if necessary.
redirectstdfd_processstdio2Redirects one standard channel to read/write from/to a file.
redirectstdio_processstdio2Redirects all 3 standard io channels to read/write from/to a file.

lifetime

init_processstdio2

static int init_processstdio2(/*out*/process_stdfd2_t *stdfd2,
process_stdio_t *stdfd)

Initializes process_stdfd2_t with process_stdio_t and opens devnull.  The device null is only opened if stdfd is 0 or at least one file descriptor is set to <iochannel_FREE>.

free_processstdio2

static int free_processstdio2(process_stdfd2_t *stdfd2)

Closes if devnull if necessary.

redirectstdfd_processstdio2

static int redirectstdfd_processstdio2(const process_stdfd2_t *stdfd2,
int stdfd,
int redirectto_file)

Redirects one standard channel to read/write from/to a file.

Parameter

stdfdThe file descriptor of the standard io channel.  Set this value to one of STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO
redirectto_fileThe file descriptor of the file which now becomes the new standard io channel.  Use value <iochannel_FREE> to redirect to devnull.  Use same value as stdfd if the standard channel should be inherited between processes.

redirectstdio_processstdio2

static int redirectstdio_processstdio2(const process_stdfd2_t *stdfd2)

Redirects all 3 standard io channels to read/write from/to a file.

If the new file descriptors have the same values as the standard channels then no redirection is done but they are inherited.

Uses redirectstdfd_processstdio2 to implement its functionality.

process_t

Summary
helper
lifetime
fork_processThis function call returns twice.
query
change

helper

lifetime

fork_process

static int fork_process(/*out*/pid_t *pid)

This function call returns twice.  It creates a new child process whihc returns from this with pid set to 0.  The calling process (parent process) gets the child’s process returned in pid.

query

change

test

Allows to creates a new process executable or a child process which executes a function.
Implements Process.
static int init_processstdio2(/*out*/process_stdfd2_t *stdfd2,
process_stdio_t *stdfd)
Initializes process_stdfd2_t with process_stdio_t and opens devnull.
struct process_stdio_t
The process standard io channel redirections.
static int free_processstdio2(process_stdfd2_t *stdfd2)
Closes if devnull if necessary.
static int redirectstdfd_processstdio2(const process_stdfd2_t *stdfd2,
int stdfd,
int redirectto_file)
Redirects one standard channel to read/write from/to a file.
static int redirectstdio_processstdio2(const process_stdfd2_t *stdfd2)
Redirects all 3 standard io channels to read/write from/to a file.
static int fork_process(/*out*/pid_t *pid)
This function call returns twice.
Close