Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7530485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:55:25+00:00 2026-05-30T04:55:25+00:00

I’m writing a Perl script (say script.pl ) that calls another script newscript.pl .

  • 0

I’m writing a Perl script (say script.pl) that calls another script newscript.pl. I want to get the PIDs of both the scripts in script.pl only. I can get the PID of script.pl by using following code

my $pid = Unix::PID->new();
my @p = $pid->get_pidof( $pid->get_command($$), 1 );

After this I call system to execute newscript.pl

system("perl newscript.pl");

I want to capture the PID generated by this newscript.pl in script.pl.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T04:55:26+00:00Added an answer on May 30, 2026 at 4:55 am

    By the time system returns, the spawned process will have already exited, leaving its pid as an interesting historical reference—useful for log analysis, for example.

    system LIST
    system PROGRAM LIST

    Does exactly the same thing as exec LIST, except that a fork is done first and the parent process waits for the child process to exit …

    If you want the pids of both script.pl and newscript.pl, fork and manage their lifetimes yourself. With more specific information about the problem you’re tackling, we could give you more specific suggestions.


    To block other instances of a program, a common technique is to use the operating system’s facility for cooperative locking: at startup, attempt to lock a certain file. If successful, your program knows it’s the only one. Otherwise, another process already has the lock, so the new process exits. See below for an example.

    #! /usr/bin/env perl
    
    use strict;
    use warnings;
    
    use Fcntl qw/ :flock /;
    use File::Basename;
    use POSIX qw/ strftime /;
    
    $0 = basename $0;
    
    my $LOCK = "$ENV{HOME}/.lock-$0";
    
    sub logmsg {
      my($msg) = @_;
      my $t = strftime "%F %T", localtime time;
      warn "$0: $t - $$ - $msg\n";
    }
    
    sub take_lock {
      open my $fh, ">", $LOCK or die "$0: open $LOCK: $!";
    
      unless (flock $fh, LOCK_EX | LOCK_NB) {
        logmsg "failed to lock $LOCK; exiting.";
        exit 1;
      }
    
      $fh;
    }
    
    my $token = take_lock;
    logmsg "processing...";
    sleep 2 * 60;
    logmsg "done.";
    

    Note that you must keep the filehandle returned from take_lock open while control is inside your critical section. The code above treats it as an opaque token. When your program exits, Perl closes the filehandle, which releases the lock automatically. What you don’t want to do is call take_lock in void context because that would discard your lock.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am writing an app with both english and french support. The app requests
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
i want to parse a xhtml file and display in UITableView. what is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.