ls *.ps | xargs -P 6 -n 1 ps2pdf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
use LWP::Simple; use Parallel::ForkManager; use File::Basename; use strict; my @gswinCommand = qw(-q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=pdfwrite);#$pdfCompatibility); my $gsBin = "c:\\Program Files (x86)\\gs\\gs8.70\\bin\\gswin32c.exe"; my $ps_input = "f:\\tmp\\thread_test\\ps"; my $pdf_output = "f:\\tmp\\thread_test\\pdf"; print join(" ",@gswinCommand) ."\n"; if (-e $gsBin){ print "found ghostview\n"; my @psFiles = glob("$ps_input\\*.ps"); my @systemCall; foreach my $psFile (@psFiles){ my($filename, $directories, $suffix) = fileparse($psFile); my $pdfFileName = $pdf_output ."\\". substr($filename,0,rindex($filename,".")) . ".pdf"; my $outputcmd = "-sOutputFile=" . $pdfFileName; my @gswinCall = ($gsBin,@gswinCommand, $outputcmd, $psFile); #print "-->" . join(" ",@gswinCall) . "<---\n"; #print "psFile = $psFile | pdf = $pdfFileName\n"; #my $result = system(@gswinCall); #print "result of last system call was $result\n"; push @psFiles,@gswinCall } my $pm = new Parallel::ForkManager(3); foreach my $convertCall (@systemCall){ $pm->start and next; my $result = system(@{$convertCall}); print "result of last system call was $result\n"; $pm->finish; # do the exit in the child process } $pm->wait_all_children; print "all processes finished\n"; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
use LWP::Simple; use Parallel::ForkManager; use File::Basename; use strict; my @gswinCommand = qw(-q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=pdfwrite);#$pdfCompatibility); my $gsBin = "c:\\Program Files (x86)\\gs\\gs8.70\\bin\\gswin32c.exe"; my $ps_input = "f:\\tmp\\thread_test\\ps"; my $pdf_output = "f:\\tmp\\thread_test\\pdf"; print join(" ",@gswinCommand) ."\n"; if (-e $gsBin){ print "found ghostview\n"; my @psFiles = glob("$ps_input\\*.ps"); my @systemCall; foreach my $psFile (@psFiles){ my($filename, $directories, $suffix) = fileparse($psFile); my $pdfFileName = $pdf_output ."\\". substr($filename,0,rindex($filename,".")) . ".pdf"; my $outputcmd = "-sOutputFile=" . $pdfFileName; my @gswinCall = ($gsBin,@gswinCommand, $outputcmd, $psFile); #print "-->" . join(" ",@gswinCall) . "<---\n"; #print "psFile = $psFile | pdf = $pdfFileName\n"; #my $result = system(@gswinCall); #print "result of last system call was $result\n"; push @systemCall,\@gswinCall; } foreach my $convertCall(@systemCall){ print "start-------------------------\n"; print "---->".join(" ", @{$convertCall}) ."<-----\n"; print "end-------------------------\n"; } my $pm = new Parallel::ForkManager(3); foreach my $convertCall (@systemCall){ # $pm->start and next; my $result = system(@{$convertCall}); print "result of last system call was $result\n"; $pm->finish; # do the exit in the child process } $pm->wait_all_children; print "all processes finished\n"; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#!/usr/bin/perl -w use strict; use Parallel::ForkManager; my $hosts2ping = "hosts2ping.txt"; my @addresses = (); open (SRC, "<$hosts2ping"); while (<SRC>) { chomp $_; push (@addresses, $_); } my $pm = new Parallel::ForkManager(10); foreach my $host (@addresses) { $pm->start and next; system("ping -n 1 -4 $host > c:\\tmp\\$host"); $pm->finish; } $pm->wait_all_children;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#!/usr/bin/perl -w use strict; use Parallel::ForkManager; my $hosts2ping = "hosts2ping.txt"; my @addresses = (); # besserer weg zum lesen der Liste: { open(my $fh, '<', $hosts2ping) or die("ERROR open $hosts2ping ($!)\n"); @addresses = <$fh>; # chomp kann auch mit Arrays umgehen chomp @addresses; close($fh); } my $pm = new Parallel::ForkManager(10); my %used; foreach my $host (@addresses) { # wenn der Host schon mal gefunden wurde # weiter zum nächsten next if $used{$host}++; $pm->start and next; system("ping -n 1 -4 $host > c:\\tmp\\$host"); $pm->finish; } $pm->wait_all_children;
QuoteIm allgemeinen ist es nicht sinnvoll mit mehren Prozessen in eine Datei zu schreiben.