SEM(1)
๐ SEM(1) โ sem ๐
okay bestie, welcome to the sem manual, and yes it's a whole vibe โจ This is the page for sem from the parallel family of tools โ she's the semaphore girlie who runs your shell command lines in parallel without breaking a sweat. ๐ธ
โจ NAME โจ
sem โ semaphore for executing shell command lines in parallel ๐
๐ฆ SYNOPSIS ๐ฆ
sem [--fg] [--id <id>] [--semaphore-timeout <secs>] [-j <num>] [--wait]
command
๐ DESCRIPTION ๐
GNU sem</purl> is literally an alias for GNU parallel --semaphore. Same girl, different name, no cap. ๐
GNU sem acts as a counting semaphore. When GNU sem is called with command it starts that command in the background. Once num number of commands are already running in the background, GNU sem just waits for one of those to finish before it starts the new command. โจ
GNU sem does not read any arguments to build the command (so no -a, no :::, no ::::). She simply waits for a semaphore to become available and then runs the command you gave her. periodt. ๐ซถ
Before you go scrolling through the options, you might wanna check out the examples down after the options list โ that'll give you the whole vibe of what GNU sem is capable of. ๐
๐ OPTIONS ๐
commandโ the command to execute. The command may be followed by arguments for the command. ๐--bgโ run command in background, soGNU semwill not wait for completion of the command before exiting. This is the default. In toilet analogy:GNU semwaits for a toilet to be available, gives the toilet to a person, and exits immediately. ๐ฝ See also:--fg--jobs N,-j N,--max-procs N,-P Nโ run up toNcommands in parallel. Default is1, so she's acting like a mutex. ๐ In toilet analogy:-jis the number of toilets. ๐ฝ๐ฝ--jobs +N,-j +N,--max-procs +N,-P +Nโ addNto the number of CPU cores. Run up to this many jobs in parallel. For compute intensive jobs-j +0is useful as it will run number-of-cpu-cores jobs simultaneously. ๐ฅ--jobs -N,-j -N,--max-procs -N,-P -Nโ subtractNfrom the number of CPU cores. Run up to this many jobs in parallel. If the evaluated number is less than1then1will be used. See also--use-cpus-instead-of-cores. ๐งฎ--jobs N%,-j N%,--max-procs N%,-P N%โ multiplyN%with the number of CPU cores. Run up to this many jobs in parallel. If the evaluated number is less than1then1will be used. See also--use-cpus-instead-of-cores. โญ--jobs procfile,-j procfile,--max-procs procfile,-P procfileโ read parameter from file. Use the content ofprocfileas parameter for-j. E.g.procfilecould contain the string100%or+2or10. ๐--pipeโ pass stdin (standard input) tocommand. Ifcommandreads from stdin (standard input), use--pipe. ๐--semaphore-name name,--id nameโ usenameas the name of the semaphore. Default is the name of the controlling tty (output fromtty). ๐ The default normally works as expected when used interactively, but when used in a scriptnameshould be set.$$ormy_task_nameare often a good value. The semaphore is stored in~/.parallel/semaphores/๐ In toilet analogy the name corresponds to different types of toilets: e.g. male, female, customer, staff. ๐ป--fgโ do not putcommandin background. In toilet analogy:GNU semwaits for a toilet to be available, takes a person to the toilet, waits for the person to finish, and exits. ๐ฝ--semaphore-timeout secs,--st secsโ ifsecs> 0: if the semaphore is not released withinsecsseconds, take it anyway. โฐ Ifsecs< 0: if the semaphore is not released withinsecsseconds, exit. ๐ญ In toilet analogy:secs> 0: if no toilet becomes available withinsecsseconds, pee on the floor.secs< 0: if no toilet becomes available withinsecsseconds, exit without doing anything. ๐--waitโ wait for all commands to complete. ๐ซถ In toilet analogy: wait until all toilets are empty, then exit. ๐ฝโจ
๐ธ UNDERSTANDING A SEMAPHORE ๐ธ
Try the following example:
sem -j 2 'sleep 1;echo 1 finished'; echo sem 1 exited
sem -j 2 'sleep 2;echo 2 finished'; echo sem 2 exited
sem -j 2 'sleep 3;echo 3 finished'; echo sem 3 exited
sem -j 2 'sleep 4;echo 4 finished'; echo sem 4 exited
sem --wait; echo sem --wait done
In toilet analogy this uses 2 toilets (-j 2). GNU sem takes '1' to a toilet, and exits immediately. While '1' is sleeping, another GNU sem takes '2' to a toilet, and exits immediately. ๐ฝ๐ฝ
While '1' and '2' are sleeping, another GNU sem waits for a free toilet. When '1' finishes, a toilet becomes available, and this GNU sem stops waiting, and takes '3' to a toilet, and exits immediately. โจ
While '2' and '3' are sleeping, another GNU sem waits for a free toilet. When '2' finishes, a toilet becomes available, and this GNU sem stops waiting, and takes '4' to a toilet, and exits immediately. ๐
Finally another GNU sem waits for all toilets to become free. ๐
๐ง EXAMPLE: Gzipping *.log ๐ง
Run one gzip process per CPU core. Block until a CPU core becomes available.
for i in *.log ; do
echo $i
sem -j+0 gzip $i ";" echo done
done
sem --wait
๐ EXAMPLE: Protecting pod2html from itself ๐
pod2html creates two files: pod2htmd.tmp and pod2htmi.tmp which it does not clean up. It uses these two files for a short time. But if you run multiple pod2html in parallel (e.g. in a Makefile with make -j) there is a risk that two different instances of pod2html will write to the files at the same time: ๐ญ
# This may fail due to shared pod2htmd.tmp/pod2htmi.tmp files
foo.html:
pod2html foo.pod --outfile foo.html
bar.html:
pod2html bar.pod --outfile bar.html
$ make -j foo.html bar.html
You need to protect pod2html from running twice at the same time. sem running as a mutex will make sure only one runs: ๐
foo.html:
sem --id pod2html pod2html foo.pod --outfile foo.html
bar.html:
sem --id pod2html pod2html bar.pod --outfile bar.html
clean: foo.html bar.html
sem --id pod2html --wait
rm -f pod2htmd.tmp pod2htmi.tmp
$ make -j foo.html bar.html clean
๐ BUGS ๐
None known. iconic behaviour honestly โจ
๐ REPORTING BUGS ๐
Report bugs to <bug-parallel@gnu.org>. ๐ง
๐ AUTHOR ๐
Copyright (C) 2010-2026 Ole Tange, http://ole.tange.dk and Free Software Foundation, Inc. ๐
๐ LICENSE ๐
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or at your option any later version. ๐
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. ๐ญ
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. ๐ซถ
๐ธ Documentation license I ๐ธ
Permission is granted to copy, distribute and/or modify this documentation under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the file LICENSES/GFDL-1.3-or-later.txt. ๐
๐ฆ Documentation license II ๐ฆ
You are free:
- to Share โ to copy, distribute and transmit the work โจ
- to Remix โ to adapt the work ๐
Under the following conditions:
- Attribution โ You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work). ๐
- Share Alike โ If you alter, transform, or build upon this work, you may distribute the resulting work only under the same, similar or a compatible license. ๐
With the understanding that:
- Waiver โ Any of the above conditions can be waived if you get permission from the copyright holder. ๐
- Public Domain โ Where the work or any of its elements is in the public domain under applicable law, that status is in no way affected by the license. โญ
- Other Rights โ In no way are any of the following rights affected by the license:
- Your fair dealing or fair use rights, or other applicable copyright exceptions and limitations; ๐
- The author's moral rights; ๐
- Rights other persons may have either in the work itself or in how the work is used, such as publicity or privacy rights. ๐
- Notice โ For any reuse or distribution, you must make clear to others the license terms of this work. ๐ข
A copy of the full license is included in the file as LICENCES/CC-BY-SA-4.0.txt. ๐
๐ DEPENDENCIES ๐
GNU sem uses Perl, and the Perl modules Getopt::Long, Symbol, Fcntl. ๐ช
โญ SEE ALSO โญ
and that's the whole page bestie, you ate it, no crumbs ๐
โจ This was SEM(1) from the parallel source, version dated 20260122 and last updated 2026-01-31 โ mwah, go run some commands in parallel, ily ๐ซถ๐
๐ฆ where this page comes from
- alpine 3.24: parallel-doc 20260322-r0 ยท GPL-3.0-or-later
- arch rolling: parallel 20260922-1 ยท GPL-3.0-only
- epel 10: parallel 20260922-2.el10_3 ยท GPL-3.0-or-later AND GFDL-1.3-or-later
- epel 9: parallel 20260922-2.el9 ยท GPL-3.0-or-later AND GFDL-1.3-or-later
- fedora 43: parallel 20260822-3.fc43
- fedora 43: parallel 20260922-2.fc43 ยท GPL-3.0-or-later AND GFDL-1.3-or-later
- fedora 44: parallel 20260222-1.fc44 ยท LicenseRef-Callaway-GFDL AND GPL-3.0-or-later
- fedora 44: parallel 20260822-3.fc44
- fedora 44: parallel 20260922-2.fc44 ยท GPL-3.0-or-later AND GFDL-1.3-or-later
- nixos 26.05: parallel 20260422
- nixpkgs unstable: parallel 20260822
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms