diff options
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | README | 2 | ||||
-rw-r--r-- | debian/changelog | 11 | ||||
-rw-r--r-- | debian/control | 1 | ||||
-rw-r--r-- | debian/copyright | 4 | ||||
-rw-r--r-- | mispipe.c | 14 | ||||
-rw-r--r-- | parallel.c | 18 | ||||
-rw-r--r-- | parallel.docbook | 116 |
8 files changed, 152 insertions, 19 deletions
@@ -1,6 +1,6 @@ BINS=isutf8 ifdata ifne pee sponge mispipe lckdo parallel PERLSCRIPTS=vidir vipe ts combine zrun -MANS=sponge.1 vidir.1 vipe.1 isutf8.1 ts.1 combine.1 ifdata.1 ifne.1 pee.1 zrun.1 mispipe.1 lckdo.1 +MANS=sponge.1 vidir.1 vipe.1 isutf8.1 ts.1 combine.1 ifdata.1 ifne.1 pee.1 zrun.1 mispipe.1 lckdo.1 parallel.1 CFLAGS=-O2 -g -Wall INSTALL_BIN?=install -s PREFIX=/usr @@ -44,5 +44,8 @@ mispipe.1: mispipe.docbook lckdo.1: lckdo.docbook $(DOCBOOK2XMAN) $< +parallel.1: parallel.docbook + $(DOCBOOK2XMAN) $< + %.1: % pod2man --center=" " --release="moreutils" $< > $@; @@ -13,6 +13,8 @@ lckdo execute a program with a lock held mispipe pipe two commands, returning the exit status of the first +parallel + run multiple jobs at once pee tee standard input to pipes sponge diff --git a/debian/changelog b/debian/changelog index 896c260..b7f0d3e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,14 @@ +moreutils (0.36) UNRELEASED; urgency=low + + * parallel: New program, contributed by Tollef Fog Heen, + that can run multiple jobs in parallel, optionally checking + load average. + * mispipe: Fix closing of extra pipe FD before starting command + so it is not inherited by daemons. Closes: #533448 + (Thanks, Jeremie Koenig) + + -- Joey Hess <joeyh@debian.org> Thu, 02 Jul 2009 14:57:12 -0400 + moreutils (0.35) unstable; urgency=low * ifdata: Don't assume that all interface names are 6 characters or less, diff --git a/debian/control b/debian/control index 7c3e652..2dbf2b2 100644 --- a/debian/control +++ b/debian/control @@ -30,3 +30,4 @@ Description: additional unix utilities - mispipe: pipe two commands, returning the exit status of the first - isutf8: check if a file or standard input is utf-8 - lckdo: execute a program with a lock held + - parallel: run multiple jobs at once diff --git a/debian/copyright b/debian/copyright index c689a57..ebe3ee7 100644 --- a/debian/copyright +++ b/debian/copyright @@ -39,6 +39,10 @@ Files: ifne.c, ifne.docbook Copyright: 2008 Javier Merino License: GPL-2+ +Files: parallel.c +Copyright: 2008 Tollef Fog Heen <tfheen@err.no> +License: GPL-2 + Files: physmem.c Copyright: 2000, 2001, 2003, 2005, 2006 Free Software Foundation, Inc. License: GPL-2+ @@ -107,15 +107,15 @@ static void subprocess2(const char* cmd) { /* Make the reading end of the pipe the new standard input. */ if (dup2(filedes[0], 0) == -1) error_with_errno("Failed (in child) redefining standard input"); + /* Close the original file descriptor for it */ + if (close(filedes[0])) + error_with_errno("Failed (in child) closing filedes[0]"); /* Close the other end of the pipe. */ if (close(filedes[1])) error_with_errno("Failed (in child) closing filedes[1]"); /* Do the second command, and throw away the exit status. */ system(cmd); - /* Close all the file descriptors. */ - if (close(filedes[0])) - error_with_errno("Failed (in child) closing filedes[0]" - " (while cleaning up)"); + /* Close the standard input. */ if (close(0)) error_with_errno("Failed (in child) closing standard output " " (while cleaning up)"); @@ -151,15 +151,15 @@ int main (int argc, const char ** argv) { /* Make the writing end of the pipe the new standard output. */ if (dup2(filedes[1], 1) == -1) error_with_errno("Failed redefining standard output"); + /* Close the original file descriptor for it. */ + if (close(filedes[1])) + error_with_errno("Failed closing filedes[1]"); /* Close the other end of the pipe. */ if (close(filedes[0])) error_with_errno("Failed closing filedes[0]"); /* Do the first command, and (crucially) get the status. */ status_big = system(argv[1]); - /* Close the pipe "standard output". */ - if (close(filedes[1])) - error_with_errno("Failed closing filedes[1] (while cleaning up)"); /* Close standard output. */ if (close(1)) error_with_errno("Failed closing standard output (while cleaning up)"); @@ -1,4 +1,3 @@ - /* * parallel.c - run commands in parallel until you run out of commands * @@ -32,15 +31,13 @@ #include <sys/types.h> #include <sys/wait.h> -void usage() -{ +void usage() { printf("parallel [OPTIONS] command -- arguments: for each argument, " "run command with argument\n"); exit(1); } -void exec_child(char **command, char *argument, int replace_cb) -{ +void exec_child(char **command, char *argument, int replace_cb) { char **argv; int argc = 0; int i; @@ -66,8 +63,7 @@ void exec_child(char **command, char *argument, int replace_cb) return; } -int wait_for_child(int options) -{ +int wait_for_child(int options) { id_t id_ignored = 0; siginfo_t infop; @@ -80,14 +76,13 @@ int wait_for_child(int options) return 1; } -int main(int argc, char **argv) -{ +int main(int argc, char **argv) { int maxjobs = -1; int curjobs = 0; int maxload = -1; int opt; char **command = calloc(sizeof(char*), argc); - char **arguments; + char **arguments = NULL; int argidx = 0; int cidx = 0; int returncode = 0; @@ -149,7 +144,8 @@ int main(int argc, char **argv) arguments[i] = strdup(argv[optind + i]); } optind += i; - } else { + } + else { command[cidx] = strdup(argv[optind]); cidx++; } diff --git a/parallel.docbook b/parallel.docbook new file mode 100644 index 0000000..07d2bf3 --- /dev/null +++ b/parallel.docbook @@ -0,0 +1,116 @@ +<?xml version="1.0" encoding="utf-8"?> + +<!-- + +Written by Joey Hess + +--> + +<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook V4.4//EN" +"file:///usr/share/xml/docbook/schema/dtd/4.4/docbookx.dtd" +[]> + +<refentry> + <refentryinfo> + <address> + <email>joey@kitenet.net</email> + </address> + <author> + <firstname>Joey</firstname> + <surname>Hess</surname> + </author> + <date>2009-07-02</date> + </refentryinfo> + + <refmeta> + <refentrytitle>parallel</refentrytitle> + <manvolnum>1</manvolnum> + </refmeta> + + <refnamediv> + <refname>parallel</refname> + <refpurpose>run programs in parallel</refpurpose> + </refnamediv> + + <refsynopsisdiv> + <cmdsynopsis> + <command>parallel</command> + <arg>options</arg> + <arg>command</arg> + <arg>--</arg> + <arg>arguments</arg> + </cmdsynopsis> + </refsynopsisdiv> + + <refsect1> + <title>DESCRIPTION</title> + + <para><command>parallel</command> runs the specified command, + passing it a single one of the specified arguments. This is + repeated for each argument. The default is to run all + the commands at the same time.</para> + + </refsect1> + + <refsect1> + <title>OPTIONS</title> + + <variablelist> + + <varlistentry> + <term><option>-j maxjobs</option></term> + <listitem> + <para>Use to limit the number of jobs + that are run at the same time.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term><option>-l maxload</option></term> + <listitem> + <para>Avoid starting new jobs when + the system's load average is higher + than the specified limit.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term><option>-i</option></term> + <listitem> + <para>Normally the command is passed the + argument at the end of its command line. With + this option, the first instance of "{}" in + the command is replaced with the argument.</para> + </listitem> + </varlistentry> + + </variablelist> + + </refsect1> + + <refsect1> + <title>EXAMPLE</title> + + <para> + <cmdsynopsis> + <command>parallel -j 3 ufraw -o processed -- *.NEF</command> + </cmdsynopsis> + </para> + + <para>This runs three ufraw processes at the same time until + all of the NEF files have been processed. + </para> + + </refsect1> + + <refsect1> + <title>EXIT STATUS</title> + + + <para>Its exit status is the combination of the exit statuses of each + command ran, ORed together. (Thus, if any one command + exists nonzero, <command>parallel</command> as a whole will exit nonzero.)</para> + + </refsect1> + +</refentry> |