LWN.net Logo

CLI Magic: Running multiple jobs with xjobs (Linux.com)

Linux.com looks at xjobs. "Ever feel like you're not getting the most out of your multiprocessor machine? The xjobs utility allows you to schedule several processes to run simultaneously to make the most of your system's resources. Xjobs takes a list of arguments from standard input and passes them to a utility, or takes a list of commands from a script, and then runs the jobs in parallel. If you have a multiprocessor machine, xjobs will automatically run one job per processor by default."
(Log in to post comments)

CLI Magic: Running multiple jobs with xjobs (Linux.com)

Posted Oct 9, 2006 18:39 UTC (Mon) by JoeBuck (subscriber, #2330) [Link]

I would recommend "make -j" instead. It will run jobs with the user-specified degree of parallelism and get dependencies right, besides, all distros already have it.

CLI Magic: Running multiple jobs with xjobs (Linux.com)

Posted Oct 9, 2006 19:18 UTC (Mon) by BlueLightning (subscriber, #38978) [Link]

There is one advantage of xjobs over make -j - you don't have to write a makefile.

CLI Magic: Running multiple jobs with xjobs (Linux.com)

Posted Oct 9, 2006 21:20 UTC (Mon) by bfields (subscriber, #19510) [Link]

It looks more like a less capable version of xargs.

And "man xargs" shows that xargs has a "--max-procs"/"-P" argument which looks like it'd accomplish essentially the same thing as xjobs, except for figuring out how many processors you have for you.

CLI Magic: Running multiple jobs with xjobs (Linux.com)

Posted Oct 9, 2006 23:09 UTC (Mon) by pjdc (guest, #6906) [Link]

This might be handy - if it's correct! I checked a dual-core-with-HT amd64 box and some UP boxes.

How many cores do I have?

$ sort -u /proc/cpuinfo | grep -c ^physical\ id
2

How many threads do I have?

$ sort -u /proc/cpuinfo | grep -c ^processor
4

CLI Magic: Running multiple jobs with xjobs (Linux.com)

Posted Oct 10, 2006 9:18 UTC (Tue) by MKallas (guest, #38539) [Link]

No need to use cat or sort to use grep:

grep -c ^processor /proc/cpuinfo

does exactly the same job.

CLI Magic: Running multiple jobs with xjobs (Linux.com)

Posted Oct 10, 2006 9:59 UTC (Tue) by nix (subscriber, #2304) [Link]

No need to use grep to use grep:

sed -n '^/processor/p' /proc/cpuinfo

does exactly the same job. (Mind you, this is only useful if you've broken grep somehow, perhaps a broken libpcre or for some reason it's not on / and you can't mount /usr, or something like that... I have found it useful in constrained environments at times, though.)

;)

CLI Magic: Running multiple jobs with xjobs (Linux.com)

Posted Oct 11, 2006 8:50 UTC (Wed) by hawk (subscriber, #3195) [Link]

That will not print the number of processors, as grep -c does... So it's not really equivalent.
(Sure, you could pipe that into wc -l, but then you'd depend on wc too.)

(And it should read "sed -n '/^processor/p' /proc/cpuinfo", right?)

CLI Magic: Running multiple jobs with xjobs (Linux.com)

Posted Oct 10, 2006 16:01 UTC (Tue) by TwoTimeGrime (guest, #11688) [Link]

> And "man xargs" shows that xargs has a "--max-procs"/"-P" argument which
> looks like it'd accomplish essentially the same thing as xjobs, except for
> figuring out how many processors you have for you.

From the <a href="http://www.maier-komor.de/xjobs.html">xjobs web page</a>:

<blockquote>
Yes, GNU's xargs has an option -P that allow parallelizing jobs. But you must tell xargs how many arguments to pass to each job, as it doesn't make a difference between a space and a newline charakter. In consequence each job issued by xargs must have the same number of arguments, whereas xjobs can handle different jobs with different commands and different number of arguments.
<p>
Additionally, xjobs support I/O redirection, which makes some applications possible that cannot be done with GNU's xargs. xjobs also determines the number of processors automatically, whereas xargs must be told how many processes to start. Finally, non-GNU xargs (e.g. Solaris' and DEC/Compaq/HP Alpha's) don't have the option -P. Try to do the following with GNU's xargs:
<p>
ls -1 *.mp3 | sed 's/\(.*\)\.mp3/"\1.mp3" > "\1.wav"/' | xjobs -- mpg123 -s
</blockquote>

Copyright © 2006, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds