| 1 | package SPVM::Sys::Process; | ||
| 2 | |||
| 3 | 1; | ||
| 4 | |||
| 5 | =head1 Name | ||
| 6 | |||
| 7 | SPVM::Sys::Process - Process System Calls | ||
| 8 | |||
| 9 | =head1 Description | ||
| 10 | |||
| 11 | Sys::Process class in L<SPVM> manipulates system calls for process manipulation. | ||
| 12 | |||
| 13 | =head1 Usage | ||
| 14 | |||
| 15 | use Sys::Process; | ||
| 16 | use Sys::Process::Constant as PROCESS; | ||
| 17 | |||
| 18 | # exit | ||
| 19 | Sys::Process->exit(PROCESS->EXIT_FAILURE); | ||
| 20 | |||
| 21 | # waitpid | ||
| 22 | my $wstatus = -1; | ||
| 23 | my $process_id = Sys::Process->waitpid($process_id, \$wstatus, PROCESS->WNOHANG); | ||
| 24 | |||
| 25 | # getpid | ||
| 26 | my $process_id = Sys::Process->getpid; | ||
| 27 | |||
| 28 | # sleep | ||
| 29 | Sys::Process->sleep(5); | ||
| 30 | |||
| 31 | =head1 Class Methods | ||
| 32 | |||
| 33 | =head2 getpid | ||
| 34 | |||
| 35 | C<static method getpid : int ();> | ||
| 36 | |||
| 37 | Calls the L<getpid|https://linux.die.net/man/2/getpid> function and returns its return value. | ||
| 38 | |||
| 39 | =head2 exit | ||
| 40 | |||
| 41 | C<static method exit : int ($status : int);> | ||
| 42 | |||
| 43 | Calls the L<exit|https://linux.die.net/man/3/exit> function and returns its return value. | ||
| 44 | |||
| 45 | See L<Sys::Process::Constant|SPVM::Sys::Process::Constant> about constant values given to $satus. | ||
| 46 | |||
| 47 | =head2 system | ||
| 48 | |||
| 49 | C<static method system : int ($command : string);> | ||
| 50 | |||
| 51 | Calls the L<system|https://linux.die.net/man/3/system> function and returns its return value. | ||
| 52 | |||
| 53 | Exceptions: | ||
| 54 | |||
| 55 | If the system function failed, an exception is thrown with C<eval_error_id> set to the basic type ID of the L<Error::System|SPVM::Error::System> class. | ||
| 56 | |||
| 57 | =head2 pipe | ||
| 58 | |||
| 59 | C<static method pipe : int ($pipe_fds : int[]);> | ||
| 60 | |||
| 61 | Calls the L<pipe|https://linux.die.net/man/2/pipe> function and returns its return value. | ||
| 62 | |||
| 63 | Windows: | ||
| 64 | |||
| 65 | Calls the L<_pipe|https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/pipe?view=msvc-170> function with size C<4096> and mode C<_O_BINARY> and returns its return value. | ||
| 66 | |||
| 67 | Exceptions: | ||
| 68 | |||
| 69 | $pipefds must be defined. Otherwise an exception is thrown. | ||
| 70 | |||
| 71 | The length of $pipefds must 2. Otherwise an exception is thrown. | ||
| 72 | |||
| 73 | If the pipe function failed, an exception is thrown with C<eval_error_id> set to the basic type ID of the L<Error::System|SPVM::Error::System> class. | ||
| 74 | |||
| 75 | In Windows, the following exception is thrown with C<eval_error_id> set to the basic type ID of L<Error::NotSupported|SPVM::Error::NotSupported> class. pipe is not supported in this system(defined(_WIN32)). | ||
| 76 | |||
| 77 | =head2 sleep | ||
| 78 | |||
| 79 | C<static method sleep : int ($seconds : int);> | ||
| 80 | |||
| 81 | Calls the L<sleep|https://linux.die.net/man/3/sleep> function and returns its return value. | ||
| 82 | |||
| 83 | =head2 usleep | ||
| 84 | |||
| 85 | C<static method usleep : int ($usec : int);> | ||
| 86 | |||
| 87 | Calls the L<usleep|https://linux.die.net/man/3/usleep> function and returns its return value. | ||
| 88 | |||
| 89 | If the usleep function failed, an exception is thrown with C<eval_error_id> set to the basic type ID of the L<Error::System|SPVM::Error::System> class. | ||
| 90 | |||
| 91 | =head2 execvp | ||
| 92 | |||
| 93 | C<static method execvp : int ($path : string, $args : string[]);> | ||
| 94 | |||
| 95 | Calls the L<execvp|https://linux.die.net/man/3/execvp> function and returns its return value. | ||
| 96 | |||
| 97 | Exceptions: | ||
| 98 | |||
| 99 | $path must be defined. Otherwise an exception is thrown. | ||
| 100 | |||
| 101 | $args must be defined. Otherwise an exception is thrown. | ||
| 102 | |||
| 103 | All element of $args must be defined. Otherwise an exception is thrown. | ||
| 104 | |||
| 105 | If the execvp function failed, an exception is thrown with C<eval_error_id> set to the basic type ID of the L<Error::System|SPVM::Error::System> class. | ||
| 106 | |||
| 107 | =head2 fork | ||
| 108 | |||
| 109 | C<static method fork : int ();> | ||
| 110 | |||
| 111 | Calls the L<fork|https://linux.die.net/man/2/fork> function and returns its return value. | ||
| 112 | |||
| 113 | Exceptions: | ||
| 114 | |||
| 115 | If the fork function failed, an exception is thrown with C<eval_error_id> set to the basic type ID of the L<Error::System|SPVM::Error::System> class. | ||
| 116 | |||
| 117 | In Windows, the following exception is thrown with C<eval_error_id> set to the basic type ID of L<Error::NotSupported|SPVM::Error::NotSupported> class. fork is not supported in this system(defined(_WIN32)). | ||
| 118 | |||
| 119 | =head2 getpriority | ||
| 120 | |||
| 121 | C<static method getpriority : int ($which : int, $who : int);> | ||
| 122 | |||
| 123 | Calls the L<getpriority|https://linux.die.net/man/2/getpriority> function and returns its return value. | ||
| 124 | |||
| 125 | See L<Sys::Process::Constant|SPVM::Sys::Process::Constant> about constant values given to $which. | ||
| 126 | |||
| 127 | Exceptions: | ||
| 128 | |||
| 129 | If the getpriority function failed, an exception is thrown with C<eval_error_id> set to the basic type ID of the L<Error::System|SPVM::Error::System> class. | ||
| 130 | |||
| 131 | In Windows, the following exception is thrown with C<eval_error_id> set to the basic type ID of L<Error::NotSupported|SPVM::Error::NotSupported> class. getpriority is not supported in this system(defined(_WIN32)). | ||
| 132 | |||
| 133 | =head2 setpriority | ||
| 134 | |||
| 135 | C<static method setpriority : int ($which : int, $who : int, $prio : int);> | ||
| 136 | |||
| 137 | Calls the L<setpriority|https://linux.die.net/man/2/setpriority> function and returns its return value. | ||
| 138 | |||
| 139 | See L<Sys::Process::Constant|SPVM::Sys::Process::Constant> about constant values given to $which. | ||
| 140 | |||
| 141 | Exceptions: | ||
| 142 | |||
| 143 | If the setpriority function failed, an exception is thrown with C<eval_error_id> set to the basic type ID of the L<Error::System|SPVM::Error::System> class. | ||
| 144 | |||
| 145 | In Windows, the following exception is thrown with C<eval_error_id> set to the basic type ID of L<Error::NotSupported|SPVM::Error::NotSupported> class. setpriority is not supported in this system(defined(_WIN32)). | ||
| 146 | |||
| 147 | =head2 wait | ||
| 148 | |||
| 149 | C<static method wait : int ($wstatus_ref : int*);> | ||
| 150 | |||
| 151 | Calls the L<wait|https://linux.die.net/man/2/wait> function and returns its return value. | ||
| 152 | |||
| 153 | Exceptions: | ||
| 154 | |||
| 155 | If the wait function failed, an exception is thrown with C<eval_error_id> set to the basic type ID of the L<Error::System|SPVM::Error::System> class. | ||
| 156 | |||
| 157 | In Windows, the following exception is thrown with C<eval_error_id> set to the basic type ID of L<Error::NotSupported|SPVM::Error::NotSupported> class. wait is not supported in this system(defined(_WIN32)). | ||
| 158 | |||
| 159 | =head2 waitpid | ||
| 160 | |||
| 161 | C<static method waitpid : int ($pid : int, $wstatus_ref : int*, $options : int);> | ||
| 162 | |||
| 163 | Calls the L<waitpid|https://linux.die.net/man/2/waitpid> function and returns its return value. | ||
| 164 | |||
| 165 | See L<Sys::Process::Constant|SPVM::Sys::Process::Constant> about constant values given to $options. | ||
| 166 | |||
| 167 | Exceptions: | ||
| 168 | |||
| 169 | The reference of the output wait status $wstatus_ref must be defined. Otherwise an exception is thrown. | ||
| 170 | |||
| 171 | If the waitpid function failed, an exception is thrown with C<eval_error_id> set to the basic type ID of the L<Error::System|SPVM::Error::System> class. | ||
| 172 | |||
| 173 | In Windows, the following exception is thrown with C<eval_error_id> set to the basic type ID of L<Error::NotSupported|SPVM::Error::NotSupported> class. waitpid is not supported in this system(defined(_WIN32)). | ||
| 174 | |||
| 175 | =head2 getpgid | ||
| 176 | |||
| 177 | C<static method getpgid : int ($pid : int);> | ||
| 178 | |||
| 179 | Calls the L<getpgid|https://linux.die.net/man/2/getpgid> function and returns its return value. | ||
| 180 | |||
| 181 | Exceptions: | ||
| 182 | |||
| 183 | If the getpgid function failed, an exception is thrown with C<eval_error_id> set to the basic type ID of the L<Error::System|SPVM::Error::System> class. | ||
| 184 | |||
| 185 | In Windows, the following exception is thrown with C<eval_error_id> set to the basic type ID of L<Error::NotSupported|SPVM::Error::NotSupported> class. getpgid is not supported in this system(defined(_WIN32)). | ||
| 186 | |||
| 187 | =head2 setpgid | ||
| 188 | |||
| 189 | C<static method setpgid : int ($pid : int, $pgid : int);> | ||
| 190 | |||
| 191 | Calls the L<setpgid|https://linux.die.net/man/2/setpgid> function and returns its return value. | ||
| 192 | |||
| 193 | Exceptions: | ||
| 194 | |||
| 195 | If the setpgid function failed, an exception is thrown with C<eval_error_id> set to the basic type ID of the L<Error::System|SPVM::Error::System> class. | ||
| 196 | |||
| 197 | In Windows, the following exception is thrown with C<eval_error_id> set to the basic type ID of L<Error::NotSupported|SPVM::Error::NotSupported> class. setpgid is not supported in this system(defined(_WIN32)). | ||
| 198 | |||
| 199 | =head2 getppid | ||
| 200 | |||
| 201 | C<static method getppid : int ();> | ||
| 202 | |||
| 203 | Calls the L<getppid|https://linux.die.net/man/2/getppid> function and returns its return value. | ||
| 204 | |||
| 205 | =head2 setsid | ||
| 206 | |||
| 207 | C<static method setsid : int ();> | ||
| 208 | |||
| 209 | Calls the L<WIFCONTINUED|https://linux.die.net/man/2/setsid> function and returns its return value. | ||
| 210 | |||
| 211 | =head2 WIFEXITED | ||
| 212 | |||
| 213 | C<static method WIFEXITED : int ($wstatus : int);> | ||
| 214 | |||
| 215 | Calls the L<WIFEXITED|https://linux.die.net/man/2/waitpid> function and returns its return value. | ||
| 216 | |||
| 217 | =head2 WEXITSTATUS | ||
| 218 | |||
| 219 | C<static method WEXITSTATUS : int ($wstatus : int);> | ||
| 220 | |||
| 221 | Calls the L<WEXITSTATUS|https://linux.die.net/man/2/waitpid> function and returns its return value. | ||
| 222 | |||
| 223 | =head2 WIFSIGNALED | ||
| 224 | |||
| 225 | C<static method WIFSIGNALED : int ($wstatus : int);> | ||
| 226 | |||
| 227 | Calls the L<WIFSIGNALED|https://linux.die.net/man/2/waitpid> function and returns its return value. | ||
| 228 | |||
| 229 | =head2 WTERMSIG | ||
| 230 | |||
| 231 | C<static method WTERMSIG : int ($wstatus : int);> | ||
| 232 | |||
| 233 | Calls the L<WTERMSIG|https://linux.die.net/man/2/waitpid> function and returns its return value. | ||
| 234 | |||
| 235 | =head2 WCOREDUMP | ||
| 236 | |||
| 237 | C<static method WCOREDUMP : int ($wstatus : int);> | ||
| 238 | |||
| 239 | Calls the L<WCOREDUMP|https://linux.die.net/man/2/waitpid> function and returns its return value. | ||
| 240 | |||
| 241 | =head2 WIFSTOPPED | ||
| 242 | |||
| 243 | C<static method WIFSTOPPED : int ($wstatus : int);> | ||
| 244 | |||
| 245 | Calls the L<WIFSTOPPED|https://linux.die.net/man/2/waitpid> function and returns its return value. | ||
| 246 | |||
| 247 | =head2 WSTOPSIG | ||
| 248 | |||
| 249 | C<static method WSTOPSIG : int ($wstatus : int);> | ||
| 250 | |||
| 251 | Calls the L<WSTOPSIG|https://linux.die.net/man/2/waitpid> function and returns its return value. | ||
| 252 | |||
| 253 | =head2 WIFCONTINUED | ||
| 254 | |||
| 255 | C<static method WIFCONTINUED : int ($wstatus : int);> | ||
| 256 | |||
| 257 | Calls the L<WIFCONTINUED|https://linux.die.net/man/2/waitpid> function and returns its return value. | ||
| 258 | |||
| 259 | =head2 spawnvp_nowait | ||
| 260 | |||
| 261 | C<static method spawnvp_nowait : int ($path : string, $args : string[]);> | ||
| 262 | |||
| 263 | Calls the L<_wspawnvp|https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/spawnvp-wspawnvp> function with _P_NOWAIT mode and returns the process ID of the spawned process. | ||
| 264 | |||
| 265 | Exceptions: | ||
| 266 | |||
| 267 | $path must be defined. Otherwise an exception is thrown. | ||
| 268 | |||
| 269 | $args must be defined. Otherwise an exception is thrown. | ||
| 270 | |||
| 271 | All element of $args must be defined. Otherwise an exception is thrown. | ||
| 272 | |||
| 273 | If _wspawnvp function failed, an exception is thrown with eval_error_id set to the basic type ID of the LError::System|SPVM::Error::System class. | ||
| 274 | |||
| 275 | In systems other than Windows, the following exception is thrown with eval_error_id set to the basic type ID of LError::NotSupported|SPVM::Error::NotSupported class. | ||
| 276 | |||
| 277 | =head1 See Also | ||
| 278 | |||
| 279 | =over 2 | ||
| 280 | |||
| 281 | =item * L<Sys|SPVM::Sys> | ||
| 282 | |||
| 283 | =back | ||
| 284 | |||
| 285 | =head1 Copyright & License | ||
| 286 | |||
| 287 | Copyright (c) 2023 Yuki Kimoto | ||
| 288 | |||
| 289 | MIT License | ||
| 290 |