PageRenderTime 16ms CodeModel.GetById 11ms app.highlight 1ms RepoModel.GetById 2ms app.codeStats 0ms

/swatch-3.2.3/tools/reswatch

#
Perl | 37 lines | 26 code | 10 blank | 1 comment | 4 complexity | da6f99147c6bd8d49312823eba76d6d1 MD5 | raw file
 1#!/usr/bin/perl
 2
 3=head1 NAME
 4
 5reswatch - Restart Swatch
 6
 7=head1 DESCRIPTION
 8
 9B<Reswatch> attempts to send a HUP signal to a swatch process. It finds the 
10process ID of B<swatch> by looking for a file named I<.swatch_script.>B<PID>
11in the home directory.
12
13=head1 SEE ALSO
14
15b<swatch(1)>
16
17=cut
18
19use DirHandle;
20
21my $script_prefix = '.swatch_script';
22my $homedir = $ENV{'HOME'};
23my $dh = new DirHandle $homedir;
24
25if (defined $dh) {
26  while (defined($_ = $dh->read)) {
27    if (/^${script_prefix}\.[0-9]*/) {
28      split(/\./, $_);;
29      print "Sending HUP signal to PID $_[$#_]\n";
30      kill('HUP', $_[$#_]);
31      undef $dh;
32      exit 0;
33    }
34  }
35}
36undef $dh;
37exit 1;