Perl6-Pugs
view release on metacpan or search on metacpan
docs/Perl6/Spec/Functions.pod view on Meta::CPAN
our OS::PW multi OS::getpw( Int $uid )
our OS::PW multi OS::getpw( Str $name )
our OS::PW multi method OS::PWEnt::getpw( OS::PWEnt $pw: )
our OS::PW multi method OS::PWEnt::getpw( OS::PWEnt $pw: Int $uid )
our OS::PW multi method OS::PWEnt::getpw( OS::PWEnt $pw: Str $name )
The C<getpw> function operates on system login information, returning
data about users in the form of an C<OS::PW> object ("PW" refers
to the historical C<getpw*> functions that are part of the POSIX
standard, and stands for "password").
When given no parameters, the "next" user entry is returned (C<undef> is
returned when the list of users has been exhausted).
When C<$uid> is provided, a user with the given UID is found and returned.
C<undef> is returned if no matching entry is found.
When C<$name> is provided, a user with the matching name is found and
returned. C<undef> is returned if no matching entry is found.
The return value is an object that represents the system-specific
information about the user. When numified, this object returns the
UID of the user. When stringified, this object returns the username.
Therefore, the typical convention of:
my Int $uid = getpw(~$name);
and
my Str $name = getpw(+$uid);
Will work as expected.
See the documentation for the C<OS::PW> and C<OS::PWEnt> classes for more
information and the equivalent of the Perl 5 setpwent / endpwent functions.
WARNING: Even when used as a method on an C<OS::PWEnt> object, there
may be system-specific, global state associated with the implementation
of these routines.
[Note: TODO setpgrp setpriority times -ajs ]
=item chroot
our Bool multi OS::chroot ( Str $path = CALLER::<$_> )
On POSIX systems, changes the context of the current process such
that the "root" directory becomes C<$path> and all rooted paths
(those that begin with a leading path separator) are relative to
that path. For security reasons, many operating systems limit
this functionality to the superuser. The return value will be
true on success.
=item getlogin
our Str multi OS::getlogin ()
Returns the username of the account running the program. This may
not be as secure as using C<getpwuid> on some platforms.
=item kill
our Bool multi OS::kill ( OS::Signal $signal, Bool :$group, *@pids )
our Bool multi method Conc::Proc::kill ( Conc::Proc $pid: OS::Signal $signal?, Bool :$group )
Sends the given C<$signal> to the process(es) given and returns a boolean
value indicating success (true) if all of the processes existed and were
sent the signal and failure (false) if any of the processes did not exist
or the signal could not be delivered to them.
The C<$signal> can be initialized from an integer signal number or a
string. Common signals are:
KILL - stop the process, do not allow it to exit gracefully
TERM - stop the process, allow it to exit gracefully
HUP - Hangup, often used as a request to re-run from scratch
STOP - Pause execution
CONT - Continue after a STOP
Consult your operating system documentation for the full list
of signal names and numbers. For compatibility, a signal name
may be prefixed with "SIG".
The method form may omit the signal. In this case, the default signal is
C<'TERM'>.
If the C<:group> named parameter is passed, C<kill> will attempt to
send the signal to a process I<group> rather than a single process.
This functionality is platform-specific.
The special signal C<0> can be sent which does not actually deliver a
signal at all, and is used to determine if processes are still running:
say "Still running" if $proc.kill(0);
=item run
our Conc::Proc::Status multi OS::run ( ; Str $command )
our Conc::Proc::Status multi OS::run ( ; Str $path, *@args )
our Conc::Proc::Status multi OS::run ( Str @path_and_args )
our Conc::Proc multi OS::run ( ; Str $command, Bool :$bg! )
our Conc::Proc multi OS::run ( ; Str $path, Bool :$bg!, *@args )
our Conc::Proc multi OS::run ( Str @path_and_args, Bool :$bg! )
C<run> executes an external program, and returns control to the caller
once the program has exited.
The default form expects a single string argument which contains the
full command-line. This command-line will be scanned for special
characters that the operating system's shell might interpret such as
C<;> or embedded quotes. If any are found, the command will be run
through a sub-shell in an operating system specific fashion (on
POSIX systems, this means C<sh -c>).
If called like this:
run( :path<'/some/path'>, 'arg1', 'arg2', ... )
( run in 3.532 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )