lib/scripts/process
author wenzelm
Fri Jan 01 16:40:47 2016 +0100 (2016-01-01)
changeset 62028 2ecee4679f99
parent 39583 c1e9c6dfeff8
permissions -rwxr-xr-x
updated for release;
wenzelm@35023
     1
#!/usr/bin/env perl
wenzelm@26092
     2
#
wenzelm@26092
     3
# Author: Makarius
wenzelm@26092
     4
#
wenzelm@39576
     5
# exec process - with optional process group and report of pid
wenzelm@26092
     6
#
wenzelm@26092
     7
wenzelm@35023
     8
use warnings;
wenzelm@35023
     9
use strict;
wenzelm@35023
    10
wenzelm@39583
    11
# process group
wenzelm@26092
    12
wenzelm@39583
    13
my $group = $ARGV[0]; shift(@ARGV);
wenzelm@26092
    14
wenzelm@26096
    15
if ($group eq "group") {
wenzelm@26096
    16
  use POSIX "setsid";
wenzelm@26107
    17
  POSIX::setsid || die $!;
wenzelm@26096
    18
}
wenzelm@26092
    19
wenzelm@39576
    20
wenzelm@39583
    21
# report pid
wenzelm@39583
    22
wenzelm@39583
    23
my $pid_name = $ARGV[0]; shift(@ARGV);
wenzelm@39576
    24
wenzelm@39581
    25
if ($pid_name eq "-") {
wenzelm@39581
    26
  print "$$\n";
wenzelm@39581
    27
}
wenzelm@39581
    28
else {
wenzelm@39581
    29
  open (PID_FILE, ">", $pid_name) || die $!;
wenzelm@39581
    30
  print PID_FILE "$$";
wenzelm@39581
    31
  close PID_FILE;
wenzelm@39581
    32
}
wenzelm@26092
    33
wenzelm@26092
    34
wenzelm@39576
    35
# exec process
wenzelm@26092
    36
wenzelm@39583
    37
my $script = $ARGV[0]; shift(@ARGV);
wenzelm@39576
    38
wenzelm@39583
    39
if ($script eq "script") {
wenzelm@39583
    40
  my $cmd_line = $ARGV[0]; shift(@ARGV);
wenzelm@39583
    41
  exec $cmd_line || die $!;
wenzelm@39583
    42
}
wenzelm@39583
    43
else {
wenzelm@39583
    44
  (exec { $ARGV[0] } @ARGV) || die $!;
wenzelm@39583
    45
}
wenzelm@39583
    46