The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

Name

SPVM::Sys::Process - System Calls for Process Manipulation

Description

The Sys::Process class has methods to call system calls for process manipulation.

Usage

  use Sys::Process;
  use Sys::Process::Constant as PROCESS;
  
  # exit
  Sys::Process->exit(PROCESS->EXIT_FAILURE);
  
  # waitpid
  my $wstatus = -1;
  my $process_id = Sys::Process->waitpid($process_id, \$wstatus, PROCESS->WNOHANG);
  
  # getpid
  my $process_id = Sys::Process->getpid;
  
  # sleep
  Sys::Process->sleep(5);

Class Methods

fork

static method fork : int ();

Calls the fork function and returns its return value.

Exceptions:

If the fork function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System class.

In Windows, the following exception is thrown with eval_error_id set to the basic type ID of the Error::NotSupported class. fork is not supported in this system(defined(_WIN32)).

getpriority

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

Calls the getpriority function and returns its return value.

See Sys::Process::Constant about constant values given to $which.

Exceptions:

If the getpriority function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System class.

In Windows, the following exception is thrown with eval_error_id set to the basic type ID of the Error::NotSupported class. getpriority is not supported in this system(defined(_WIN32)).

setpriority

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

Calls the setpriority function and returns its return value.

See Sys::Process::Constant about constant values given to $which.

Exceptions:

If the setpriority function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System class.

In Windows, the following exception is thrown with eval_error_id set to the basic type ID of the Error::NotSupported class. setpriority is not supported in this system(defined(_WIN32)).

sleep

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

Calls the sleep function and returns its return value.

usleep

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

Calls the usleep function and returns its return value.

If the usleep function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System class.

wait

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

Calls the wait function and returns its return value.

Exceptions:

If the wait function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System class.

In Windows, the following exception is thrown with eval_error_id set to the basic type ID of the Error::NotSupported class. wait is not supported in this system(defined(_WIN32)).

waitpid

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

Calls the waitpid function and returns its return value.

See Sys::Process::Constant about constant values given to $options.

Exceptions:

If the waitpid function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System class.

In Windows, the following exception is thrown with eval_error_id set to the basic type ID of the Error::NotSupported class. waitpid is not supported in this system(defined(_WIN32)).

system

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

Calls the system function and returns its return value.

Exceptions:

If the system function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System class.

exit

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

Calls the exit function and returns its return value.

See Sys::Process::Constant about constant values given to $satus.

pipe

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

Calls the pipe function and returns its return value.

Exceptions:

$pipefds must be defined. Otherwise an exception is thrown.

The length of $pipefds must 2. Otherwise an exception is thrown.

If the pipe function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System class.

In Windows, the following exception is thrown with eval_error_id set to the basic type ID of the Error::NotSupported class. pipe is not supported in this system(defined(_WIN32)).

_pipe

  static method _pipe : int ($pipe_fds : int[], $psize : int, $textmode : int);

Calls the _pipe function and returns its return value.

Exceptions:

$pipefds must be defined. Otherwise an exception is thrown.

The length of $pipefds must 2. Otherwise an exception is thrown.

If the _pipe function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System class.

In OSs other than Windows, the following exception is thrown with eval_error_id set to the basic type ID of the Error::NotSupported class. _pipe is not supported in this system(!defined(_WIN32)).

getpgid

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

Calls the getpgid function and returns its return value.

Exceptions:

If the getpgid function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System class.

In Windows, the following exception is thrown with eval_error_id set to the basic type ID of the Error::NotSupported class. getpgid is not supported in this system(defined(_WIN32)).

setpgid

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

Calls the setpgid function and returns its return value.

Exceptions:

If the setpgid function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System class.

In Windows, the following exception is thrown with eval_error_id set to the basic type ID of the Error::NotSupported class. setpgid is not supported in this system(defined(_WIN32)).

getpid

static method getpid : int ();

Calls the getpid function and returns its return value.

getppid

static method getppid : int ();

Calls the getppid function and returns its return value.

execv

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

Calls the execv function and returns its return value.

Exceptions:

$path must be defined. Otherwise an exception is thrown.

$args must be defined. Otherwise an exception is thrown.

All element of $args must be defined. Otherwise an exception is thrown.

If the execv function failed, an exception is thrown with eval_error_id set to the basic type ID of the Error::System class.

WIFEXITED

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

Calls the WIFEXITED function and returns its return value.

WEXITSTATUS

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

Calls the WEXITSTATUS function and returns its return value.

WIFSIGNALED

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

Calls the WIFSIGNALED function and returns its return value.

WTERMSIG

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

Calls the WTERMSIG function and returns its return value.

WCOREDUMP

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

Calls the WCOREDUMP function and returns its return value.

WIFSTOPPED

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

Calls the WIFSTOPPED function and returns its return value.

WSTOPSIG

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

Calls the WSTOPSIG function and returns its return value.

WIFCONTINUED

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

Calls the WIFCONTINUED function and returns its return value.

Copyright & License

Copyright (c) 2023 Yuki Kimoto

MIT License