# Pexec

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Pexec
> Markdown URL: https://mediated.wiki/source/Pexec.md
> Source: https://en.wikipedia.org/wiki/Pexec
> Source revision: 1353624216
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

{{Lowercase title}}
{{Distinguish|pkexec}}
'''pexec''' is a [command-line utility](/source/command-line_utility) for [Linux](/source/Linux) and other [Unix-like](/source/Unix-like) operating systems which allows the user to execute [shell](/source/Bourne_shell) [commands](/source/Command_(computing)) in [parallel](/source/Parallel_computing). The specified code can be executed either locally or on remote hosts, in which case [ssh](/source/Secure_Shell) is used to build a secure tunnel between them. Similar to shell loops, a variable is changed as the loop starting the tasks iterates, so that many values can get passed to the specified command or script. '''pexec''' is a [free software](/source/free_software) utility, and part of the [GNU Project](/source/GNU_Project).<ref>{{cite web|url=http://savannah.gnu.org/projects/pexec/|title=pexec - Summary|accessdate=25 June 2012}}</ref> It is available<ref>[https://www.gnu.org/software/pexec/ www.gnu.org/software/pexec/]</ref> under the terms of [GPLv3](/source/GPLv3), and is part of the current [Debian](/source/Debian) stable release.<ref>[https://packages.debian.org/stable/pexec packages.debian.org/stable/pexec]</ref>

== Usage ==
The most common usage is to replace the shell loop, for example:
<syntaxhighlight lang="bash">
 for x in alpha bravo charlie delta ; do 
     do_something $x
 done
</syntaxhighlight>
to the form of:
<syntaxhighlight lang="bash">
 pexec -r alpha bravo charlie delta -e x -o - -c \
     'do_something $x'
</syntaxhighlight>
where the set with the 4 elements of "alpha" "bravo" "charlie" and "delta" define the possible values for the (environmental)
variable $x. The program '''pexec''' features also
* automatic redirection of [standard input](/source/standard_input), [output](/source/standard_output) and [error](/source/standard_error_stream) from/to regular files;
* taking the input set from a file instead of command line argument;
* the capability for re-formatting the output and error streams;
* support for [mutual exclusions](/source/Mutex) and atomic command executions inside the shell loop (in order to, e.g. avoid unexpectedly high I/O [load](/source/Load_(computing)));
* using alternative [remote shells](/source/Remote_Shell) instead of [ssh](/source/Secure_Shell).
* using supervisor daemons to balance between the resources of concurrent '''pexec''' instances.
Such optional features can be requested using [command-line argument](/source/command-line_argument)s. By default, '''pexec''' tries to detect the number of [CPU](/source/CPU)s and uses all of them.

==See also==
{{Portal|Free and open-source software}}
* [GNU parallel](/source/GNU_parallel)
* [xargs](/source/xargs)

== References ==
{{reflist}}

== External links ==
* [https://www.gnu.org/software/pexec/pexec.1.html Manual page of pexec]
* [https://www.gnu.org/software/pexec/ Project page]

{{GNU}}

Category:GNU Project software
Category:Linux process- and task-management-related software

---
Adapted from the Wikipedia article [Pexec](https://en.wikipedia.org/wiki/Pexec) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Pexec?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
