Execució paralela amb xargs
Avui he après una nova cosa per a utilitzar en script , la opció -P de la comanda xargs.
A vegades, tens un conjunt de tasques a fer amb un script, que normalment es fan amb bucle for o directament.
Per exemple, per a comprimir tots els fitxers de un directori es pot fer
$ gzip *
o
$ for f in * ; do gzip $f ; done
Això te el problema que la feina es fa seqüencialment, i si tens un ordinador amb varis processadors o varis cores, pots millorar el rendiment si executes una procés a cada procesasdor, això es pot fer utilitzant xargs, amb la opció -P que permet dir quants processos simultanis (màxims) s’han de iniciar.
Per exemple si tenim 4 cores (Quad core)
$ ls * | xargs -P 4 -n 1 gzip
opcio -P indica numero màxim de processos a iniciar, la opció -n indica el numero de arguments de cada crida de la comanda.
Feia temps que no aprenia res nou en el món dels shell scripts, i m’agrada aprendre coses noves !!!
Pingback: CLINTON
Pingback: TIMOTHY
Pingback: CLYDE
Pingback: ANTHONY
Pingback: JIMMIE
Pingback: SERGIO
Pingback: DARRELL
Pingback: FERNANDO
Pingback: GREGORY
Pingback: ENRIQUE
Pingback: ALBERTO
Pingback: CARLTON
Pingback: ARTHUR
Pingback: KIRK
Pingback: JORDAN
Pingback: GUY
Pingback: ALVIN
Pingback: RON
Pingback: MATTHEW
Pingback: COREY
Pingback: DARRYL
Pingback: REX
Pingback: MAURICE
Pingback: RUSSELL
Pingback: CHRISTIAN
Pingback: LUTHER
Pingback: HUBERT
Pingback: CLINTON
Pingback: JULIO
Pingback: AUSTIN
Pingback: JONATHAN
Pingback: PAUL
Pingback: DONNIE
Pingback: CHRIS
Pingback: TERRANCE
Pingback: CURTIS
Pingback: DANIEL
Pingback: MANUEL
Pingback: LOUIS
Pingback: LLOYD
Pingback: GREGORY
Pingback: JOSHUA
Pingback: GARY
Pingback: JAIME
Pingback: MELVIN
Pingback: SHAUN
Pingback: DUSTIN
Pingback: DENNIS
Pingback: KURT
Pingback: JORDAN
Pingback: WAYNE
Pingback: SCOTT
Pingback: ANTONIO
Pingback: JULIAN
Pingback: LEE
Pingback: SHAUN
Pingback: MELVIN
Pingback: HARRY
Pingback: CASEY
Pingback: SALVADOR
Pingback: REX
Pingback: WESLEY
Pingback: ROBERTO
Pingback: FRANKLIN
Pingback: NORMAN
Pingback: JORDAN
Pingback: EDDIE
Pingback: ADRIAN