Scroll to navigation

Proc::Background::Unix(3pm) User Contributed Perl Documentation Proc::Background::Unix(3pm)

NAME

Proc::Background::Unix - Unix-specific implementation of process create/wait/kill

DESCRIPTION

This module does not have a public interface. Use Proc::Background.

IMPLEMENTATION

Command vs. Exec

Unix systems start a new process by creating a mirror of the current process ("fork") and then having it alter its own state to prepare for the new program, and then calling "exec" to replace the running code with code loaded from a new file. However, there is a second common method where the user wants to specify a command line string as they would type it in their shell. In this case, the actual program being executed is the shell, and the command line is given as one element of its argument list.

Perl already supports both methods, such that if you pass one string to "exec" containing shell characters, it calls the shell, and if you pass multiple arguments, it directly invokes "exec".

This module mostly just lets Perl's "exec" do its job, but also checks for the existence of the executable first, to make errors easier to catch. This check is skipped if there is a single-string command line.

Unix lets you run a different executable than what is listed in the first argument. (this feature lets one Unix executable behave as multiple different programs depending on what name it sees in the first argument) You can use that feature by passing separate options of "exe" and "command" to this module's constructor instead of a simple argument list. But, you can't mix a "exe" option with a shell-interpreted command line string.

Errors during Exec

If the "autodie" option is enabled, and the system supports "FD_CLOEXEC", this module uses a trick where the forked child relays any errors through a pipe so that the parent can throw and handle the exception directly instead of creating a child process that is dead-on-arrival with the error on STDERR.

AUTHORS

  • Blair Zajac <blair@orcaware.com>
  • Michael Conrad <mike@nrdvana.net>

VERSION

version 1.32

COPYRIGHT AND LICENSE

This software is copyright (c) 2023 by Michael Conrad, (C) 1998-2009 by Blair Zajac.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

2024-03-07 perl v5.38.2