Perl

Stay ahead with the latest trends in custom software development. Explore how AI, automation, and cloud solutions are shaping the future of business technology.

Perl – Fork and Kill a System Process on Timeout

Perl – Fork and Kill a System Process on Timeout [perl] $pid = open(PIPE, “$command |”) or die $!; eval { local $SIG{ALRM} = sub { die “TIMEOUT” }; alarm($timeout); while (<PIPE>) { $data = $_; }; close(PIPE); alarm(0); }; if ($@) { die $@ unless $@ =~ /TIMEOUT/; kill 15, $pid; close(PIPE); $? ||= […]
Continue Reading

Get Parent PID

Get Parent PID [perl] my $parent_id = getppid(); print "$parent_id\n"; [/perl] NAME getppid – get parent process ID SYNOPSIS getppid DESCRIPTION Returns the process id of the parent process. DISCLAIMER We are painfully aware that these documents may contain incorrect links and misformatted HTML. Such bugs lie in the automatic translation process that automatically created […]
Continue Reading

Perl – Lock Files (flock)

Perl – Lock Files (flock) The following script is an example of using lock files in Perl. This prevents more than one user or process accessing a file at a time. [perl] use Fcntl qw(:DEFAULT :flock); use Fcntl ‘:flock’;¬†¬†¬†¬† #LOCK_* constants my($lockneedsremoving)=0; my($lockfilename)=”/var/.pwd.lock”; unless (createlock()) { print “Lock has been created”; print “This is only […]
Continue Reading

Perl Substr

Perl Substr substr This function supports three sets of passed values as follows: [perl] substr (STRING,OFFSET,LEN,REPLACEMENT) substr (STRING,OFFSET,LEN) substr (STRING,OFFSET) [/perl] The function: substr (STRING,OFFSET) returns all characters in the string after the designated offset from the start of the passed string. The function: substr (STRING,OFFSET,LEN) returns all characters in the string after the designated […]
Continue Reading