#include <unistd.h>
void usage() {
- printf("parallel [OPTIONS] command -- arguments: for each argument, "
- "run command with argument\n");
+ printf("parallel [OPTIONS] command -- arguments\n\tfor each argument, "
+ "run command with argument, in parallel\n");
+ printf("parallel [OPTIONS] -- commands\n\trun specified commands in parallel\n");
exit(1);
}
if (replace_cb == 0)
argc++;
argv = calloc(sizeof(char*), argc + nargs);
- for (i = 0; i < argc; i++) {
- argv[i] = command[i];
- if (replace_cb && (strcmp(argv[i], "{}") == 0))
- argv[i] = arguments[0];
+ if (command[0]) {
+ for (i = 0; i < argc; i++) {
+ argv[i] = command[i];
+ if (replace_cb && (strcmp(argv[i], "{}") == 0))
+ argv[i] = arguments[0];
+ }
+ if (replace_cb == 0)
+ memcpy(argv + i - 1, arguments, nargs * sizeof(char *));
+ if (fork() == 0) {
+ /* Child */
+ execvp(argv[0], argv);
+ exit(1);
+ }
}
- if (replace_cb == 0)
- memcpy(argv + i - 1, arguments, nargs * sizeof(char *));
- if (fork() == 0) {
- /* Child */
- execvp(argv[0], argv);
- exit(1);
+ else {
+ if (fork() == 0) {
+ exit(system(arguments[0]));
+ }
}
return;
}
int replace_cb = 0;
char *t;
- while ((opt = getopt(argc, argv, "+hij:l:n:")) != -1) {
+ while ((argv[optind] && strcmp(argv[optind], "--") != 0) &&
+ (opt = getopt(argc, argv, "+hij:l:n:")) != -1) {
switch (opt) {
case 'h':
usage();
break;
}
}
-
+
if (replace_cb && argsatonce > 1) {
fprintf(stderr, "options -i and -n are incomaptible\n");
exit(2);
maxjobs = 1;
#endif
}
-
+
while (optind < argc) {
if (strcmp(argv[optind], "--") == 0) {
int i;
optind++;
}
+ if (argsatonce > 1 && ! command[0]) {
+ fprintf(stderr, "option -n cannot be used without a command\n");
+ exit(2);
+ }
+
while (argidx < arglen) {
double load;
<command>parallel</command>
<arg>options</arg>
<arg>command</arg>
- <arg>--</arg>
- <arg>arguments</arg>
+ <command>--</command>
+ <arg>argument ...</arg>
+ </cmdsynopsis>
+ <cmdsynopsis>
+ <command>parallel</command>
+ <arg>options</arg>
+ <command>--</command>
+ <arg>command ...</arg>
</cmdsynopsis>
</refsynopsisdiv>
repeated for each argument. Jobs may be run in
parallel. The default is to run one job per CPU.</para>
+ <para>If no command is specified before the --,
+ the commands after it are instead run in parallel.</para>
+
</refsect1>
<refsect1>
<para>This runs three ufraw processes at the same time until
all of the NEF files have been processed.
</para>
+
+ <para>
+ <cmdsynopsis>
+ <command>parallel -j 3 -- ls df "echo hi"</command>
+ </cmdsynopsis>
+ </para>
+
+ <para>This runs three independent commands in parallel.</para>
</refsect1>