Name

SPVM::Sys::Process - Process System Call

Usage

use Sys::Process;
use Sys::Process::Constant as PROCESS;

# exit
Sys::Process->exit(PROCESS->EXIT_FAILURE);

# waitpid
my $wstatus;
my $changed_process_id = Sys::Process->waitpid($process_id, \$wstatus, PROCESS->WNOHANG);

# getpid
my $process_id = Sys::Process->getpid;

# sleep
Sys::Process->sleep(5);

Description

Sys::Process provides the methods to call the system call for the process manipulation.

Class Methods

fork

static method fork : int ();

fork() creates a new process by duplicating the calling process. The new process, referred to as the child, is an exact duplicate of the calling process, referred to as the parent, except for the following points:

See the detail of the fork function in the case of Linux.

getpriority

static method getpriority : int ($which : int, $who : int);

The scheduling priority of the process, process group, or user, as indicated by which and who is obtained with the getpriority() call and set with the setpriority() call.

See the detail of the getpriority function in the case of Linux.

setpriority

static method setpriority : int ($which : int, $who : int, $prio : int);

The scheduling priority of the process, process group, or user, as indicated by which and who is obtained with the getpriority() call and set with the setpriority() call.

See the detail of the setpriority function in the case of Linux.

sleep

static method sleep : int ($seconds : int);

sleep() makes the calling thread sleep until seconds seconds have elapsed or a signal arrives which is not ignored.

See the detail of the sleep function in the case of Linux.

wait

static method wait : int ($wstatus : int*);

All of these system calls are used to wait for state changes in a child of the calling process, and obtain information about the child whose state has changed. A state change is considered to be: the child terminated; the child was stopped by a signal; or the child was resumed by a signal. In the case of a terminated child, performing a wait allows the system to release the resources associated with the child; if a wait is not performed, then the terminated child remains in a "zombie" state (see NOTES below).

See the detail of the wait function in the case of Linux.

See "Waiting Status Checking Methods" about checking the waiting status.

waitpid

static method waitpid : int ($pid : int, $wstatus : int*, $options : int);

All of these system calls are used to wait for state changes in a child of the calling process, and obtain information about the child whose state has changed. A state change is considered to be: the child terminated; the child was stopped by a signal; or the child was resumed by a signal. In the case of a terminated child, performing a wait allows the system to release the resources associated with the child; if a wait is not performed, then the terminated child remains in a "zombie" state (see NOTES below).

See the detail of the waitpid function in the case of Linux.

See Sys::Process::Constant about the constant value for the options.

See "Waiting Status Checking Methods" about checking the waiting status.

system

static method system : int ($command : string);

system() executes a command specified in command by calling /bin/sh -c command, and returns after the command has been completed. During execution of the command, SIGCHLD will be blocked, and SIGINT and SIGQUIT will be ignored.

See the detail of the system function in the case of Linux.

See "Waiting Status Checking Methods" about checking the return value.

exit

static method exit : int ($status : int);

The exit() function causes normal process termination and the value of status & 0377 is returned to the parent (see wait(2)).

See the detail of the exit function in the case of Linux.

See Sys::Process::Constant about the constant value for the status.

pipe

static method pipe : int ($pipe_fds : int[]);

pipe() creates a pipe, a unidirectional data channel that can be used for interprocess communication. The array pipefd is used to return two file descriptors referring to the ends of the pipe. pipefd[0] refers to the read end of the pipe. pipefd[1] refers to the write end of the pipe. Data written to the write end of the pipe is buffered by the kernel until it is read from the read end of the pipe. For further details, see pipe(7).

See the detail of the pipe function in the case of Linux.

getpgid

static method getpgid : int ($pid : int);

All of these interfaces are available on Linux, and are used for getting and setting the process group ID (PGID) of a process. The preferred, POSIX.1-specified ways of doing this are: getpgid(void), for retrieving the calling process's PGID; and setpgid(), for setting a process's PGID.

See the detail of the getpgid function in the case of Linux.

setpgid

static method setpgid : int ($pid : int, $pgid : int);

All of these interfaces are available on Linux, and are used for getting and setting the process group ID (PGID) of a process. The preferred, POSIX.1-specified ways of doing this are: getpgid(void), for retrieving the calling process's PGID; and setpgid(), for setting a process's PGID.

See the detail of the setpgid function in the case of Linux.

getpid

static method getpid : int ();

getpid() returns the process ID of the calling process. (This is often used by routines that generate unique temporary filenames.)

See the detail of the getpid function in the case of Linux.

getppid

static method getppid : int ();

getppid() returns the process ID of the parent of the calling process.

See the detail of the getppid function in the case of Linux.

execv

static method execv : int ($path : string, $args : string[]);

The execv(), execvp(), and execvpe() functions provide an array of pointers to null-terminated strings that represent the argument list available to the new program. The first argument, by convention, should point to the filename associated with the file being executed. The array of pointers must be terminated by a NULL pointer.

See the detail of the https://linux.die.net/man/3/execv function in the case of Linux.

Waiting Status Checking Methods

WIFEXITED

static method WIFEXITED : int ($wstatus : int);

WEXITSTATUS

static method WEXITSTATUS : int ($wstatus : int);

WIFSIGNALED

static method WIFSIGNALED : int ($wstatus : int);

WTERMSIG

static method WTERMSIG : int ($wstatus : int);

WCOREDUMP

static method WCOREDUMP : int ($wstatus : int);

WIFSTOPPED

static method WIFSTOPPED : int ($wstatus : int);

WSTOPSIG

static method WSTOPSIG : int ($wstatus : int);

WIFCONTINUED

static method WIFCONTINUED : int ($wstatus : int);

usleep

static method usleep : int ($usec : int);

The usleep() function suspends execution of the calling thread for (at least) usec microseconds. The sleep may be lengthened slightly by any system activity or by the time spent processing the call or by the granularity of system timers.

See the detail of the usleep function in the case of Linux.

Copyright & License

Copyright (c) 2023 Yuki Kimoto

MIT License