Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / lib / site_perl / 5.8.0 / Psh / Builtins / Jobs.pm
CommitLineData
86530b38
AT
1package Psh::Builtins::Jobs;
2
3require Psh::Util;
4require Psh::Joblist;
5require Psh::OS;
6require Getopt::Std;
7
8=item * C<jobs [-rs] [-p]>
9
10List the currently running jobs.
11
12Option B<-r> restricts the output to display only currently running jobs.
13Option B<-s> will only show currently stopped jobs
14
15If you specify option B<-p> only the PIDs of the processes are displayed.
16
17=cut
18
19sub bi_jobs {
20 my $line= shift;
21 local @ARGV = @{shift()};
22
23 if( ! Psh::OS::has_job_control()) {
24 Psh::Util::print_error_i18n('no_jobcontrol');
25 return (0,undef);
26 }
27 my $opt={};
28 Getopt::Std::getopts('prs',$opt);
29
30 my $result = '';
31 my $job;
32 my $visindex=0;
33
34 Psh::Joblist::enumerate();
35
36 while( ($job=Psh::Joblist::each())) {
37 my $pid = $job->{pid};
38 my $command = $job->{call};
39 $visindex++;
40
41 next if $opt->{'r'} and !$job->{running};
42 next if $opt->{'s'} and $job->{running};
43
44 if ($opt->{'p'}) { # print pid's only
45 $result.= "$pid\n";
46 } else {
47 $result .= "[$visindex] $pid $command";
48
49 if ($job->{running}) { $result .= "\n"; }
50 else { $result .= ' ('.Psh::Locale::get_text('stopped').")\n"; }
51 }
52 }
53
54 if (!$result) {
55 Psh::Util::print_out_i18n('bi_jobs_none');
56 return (0,undef);
57 }
58 else {
59 Psh::Util::print_out($result);
60 return (1,undef);
61 }
62}
63
641;