© 2023 PodTECH IO
All rights reserved.

Get in Touch

Perl

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); $? ||= […]

UNIX

Amazon – Ubuntu CPAN Perl Install

Amazon – Ubuntu CPAN Perl Install If you experiencing any issues with installing, upgrading or managing CPAN perl libraries on a refreshley deployed Amazon EC2 instance make sure you have your build essentials!! Run: sudo  apt-get install build-essential    

Perl

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 […]

Perl

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 […]

Perl

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 […]

Perl

Perl Index

Perl Index index This function returns the position of the first occurance of the specified SEARCH string. If POSITION is specified, the occurance at or after the position is returned. The value -1 is returned if the SEARCH string is not found. [perl] rindex STRING,SEARCH,POSITION rindex STRING,SEARCH [/perl]