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 3305696
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:12:01+00:00 2026-05-17T21:12:01+00:00

I have a process in Perl that creates another one with the system command

  • 0

I have a process in Perl that creates another one with the system command, I leave it on memory and I pass some variables like this:


my $var1 = "Hello";
my $var1 = "World";
system "./another_process.pl $var1 $var2 &";

But the system command only returns the result, I need to get the PID. I want to make something like fork. What should I do? How can I make something like fork but in diferent scripts?

Thanks in advance!

  • 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-17T21:12:01+00:00Added an answer on May 17, 2026 at 9:12 pm

    Perl has a fork function.

    See perldoc perlfaq8 – How do I start a process in the background?


    (contributed by brian d foy)

    There’s not a single way to run code
    in the background so you don’t have to
    wait for it to finish before your
    program moves on to other tasks.
    Process management depends on your
    particular operating system, and many
    of the techniques are in perlipc.
    Several CPAN modules may be able to
    help, including
    IPC::Open2
    or
    IPC::Open3
    ,
    IPC::Run
    ,
    Parallel::Jobs
    ,
    Parallel::ForkManager
    ,
    POE
    ,
    Proc::Background
    , and
    Win32::Process
    .

    There are many other modules you might
    use, so check those namespaces for
    other options too. If you are on a
    Unix-like system, you might be able to
    get away with a system call where you
    put an & on the end of the command:

        system("cmd &")
    

    You can also try using
    fork,
    as described in
    perlfunc
    (although this is the same thing that
    many of the modules will do for you).

    STDIN, STDOUT, and STDERR are shared

    Both the main process and the
    backgrounded one (the “child” process)
    share the same STDIN, STDOUT and
    STDERR filehandles. If both try to
    access them at once, strange things
    can happen. You may want to close or
    reopen these for the child. You can
    get around this with opening a pipe
    (see open) but on some systems this
    means that the child process cannot
    outlive the parent.

    Signals

    You’ll have to catch the SIGCHLD
    signal, and possibly SIGPIPE too.
    SIGCHLD is sent when the backgrounded
    process finishes. SIGPIPE is sent when
    you write to a filehandle whose child
    process has closed (an untrapped
    SIGPIPE can cause your program to
    silently die). This is not an issue
    with system("cmd&").

    Zombies

    You have to be prepared to “reap” the
    child process when it finishes.
    $SIG{CHLD} = sub { wait };
    $SIG{CHLD} = ‘IGNORE’; You can also
    use a double fork. You immediately
    wait() for your first child, and the
    init daemon will wait() for your
    grandchild once it exits.

    unless ($pid = fork) {
            unless (fork) { 
                exec "what you really wanna do";
                die "exec failed!";
      }
    
            exit 0;
        }
    
        waitpid($pid, 0);
    

    See Signals in
    perlipc
    for other examples of code to do this.
    Zombies are not an issue with
    system("prog &").system("prog &").

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

Sidebar

Related Questions

I have some data generated in MATLAB that I want to process using Perl.
I have a Perl program that I've written that parses SQL-like statements and creates
I have a daemon process written in Perl that uses Inotify2 to watch directories
Have a perl script that needs to process all files of a certain type
I have a perl script that accepts a long option like --pager='less -R' and
I have part of a build process that creates a hideously long paths in
I have a Perl script that executes a long running process and observes its
I have a Perl script that does a fork/exec to start another tool in
I have a Perl script that launches another Perl script in a new console
I have a Perl script that reads a simple .csv file like below- header1,header2,header3,header4

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.