lib/scripts/process
author bulwahn
Wed, 10 Oct 2012 10:48:55 +0200
changeset 49768 3ecfba7e731d
parent 39583 c1e9c6dfeff8
permissions -rwxr-xr-x
adding necessary syntactic functions in set_comprehension_pointfree simproc as a first step to integrate an improved simproc

#!/usr/bin/env perl
#
# Author: Makarius
#
# exec process - with optional process group and report of pid
#

use warnings;
use strict;

# process group

my $group = $ARGV[0]; shift(@ARGV);

if ($group eq "group") {
  use POSIX "setsid";
  POSIX::setsid || die $!;
}


# report pid

my $pid_name = $ARGV[0]; shift(@ARGV);

if ($pid_name eq "-") {
  print "$$\n";
}
else {
  open (PID_FILE, ">", $pid_name) || die $!;
  print PID_FILE "$$";
  close PID_FILE;
}


# exec process

my $script = $ARGV[0]; shift(@ARGV);

if ($script eq "script") {
  my $cmd_line = $ARGV[0]; shift(@ARGV);
  exec $cmd_line || die $!;
}
else {
  (exec { $ARGV[0] } @ARGV) || die $!;
}