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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:32:41+00:00 2026-06-11T23:32:41+00:00

I am using Linux and .sh is in tcsh . I have made a

  • 0

I am using Linux and .sh is in tcsh.

I have made a very basic fork and exec, but I need help in implementing safeties to it.

Basically my perl script calls a .sh script in a child process. But when I do Ctrl+c to kill the parent, the signal gets ignored by the child.

1) How do I capture the SIGINT for the child process as well?

2) The child process that runs the .sh script still STDOUT to the screen of the xterm. How can I remove this? I was thinking of doing running the script in the background

 exec("shell.sh args &");  

But haven’t tested as I need to figure out how to keep the child from going wild first.

3) The parent process(perl script) doesn’t wait on the child(.sh script). So I’ve read a lot about the child becoming a zombie??? Will it happen after the script is done? And how would I stop it?

$pid = fork();
if($pid < 0){
    print "Failed to fork process... Exiting";
    exit(-1);
    }
elsif ($pid ==0) {
    #child process
    exec("shell.sh args");
    exit(1);
    }
else { #execute rest of parent}
  • 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-06-11T23:32:42+00:00Added an answer on June 11, 2026 at 11:32 pm

    But when I do ctrl+c to kill the parent, the signal gets ignored by the child.

    The signal is sent to two both the parent and the child.

    $ perl -E'
       if (my $pid = fork()) {
          local $SIG{INT} = sub { say "Parent got SIGINT" };
          sleep;
          waitpid($pid, 0);
       } else {
          local $SIG{INT} = sub { say "Child got SIGINT" };
          sleep;
       }
    '
    ^CParent got SIGINT
    Child got SIGINT
    

    If that child ignores it, it’s because it started a new session or because it explicitly ignores it.

    The child procces that runs the .sh script still STDOUT to the screen of the xterm. How can I remove this?

    Do the following in the child before calling exec:

    open(STDOUT, '>', '/dev/null');
    open(STDERR, '>', '/dev/null');
    

    Actually, I would use open3 to get some error checking.

    open(local *CHILD_STDIN,  '<', '/dev/null') or die $!;
    open(local *CHILD_STDOUT, '>', '/dev/null') or die $!;
    my $pid = open3(
       '<&CHILD_STDIN',
       '>&CHILD_STDOUT',
       '>&CHILD_STDOUT',
       'shell.sh', 'args',
    );
    

    The parent process(perl script) doesn’t wait on the child(.sh script). So I’ve read alot about the child becoming a zombie???

    Children are automatically reaped when the parent exits, or if they exit after the parent exits.

    $ perl -e'
       for (1..3) {
          exec(perl => (-e => 1)) if !fork;
       }
       sleep 1;
       system("ps");
    ' ; ps
      PID TTY          TIME CMD
    26683 pts/13   00:00:00 bash
    26775 pts/13   00:00:00 perl
    26776 pts/13   00:00:00 perl <defunct>       <-- zombie
    26777 pts/13   00:00:00 perl <defunct>       <-- zombie
    26778 pts/13   00:00:00 perl <defunct>       <-- zombie
    26779 pts/13   00:00:00 ps
      PID TTY          TIME CMD
    26683 pts/13   00:00:00 bash
    26780 pts/13   00:00:00 ps
                                                 <-- all gone
    

    If the parent exits before the children do, there’s no problem.

    If the parent exits shortly after the children do, there’s no problem.

    If the parent exits a long time after the children do, you’ll want to reap them. You could do that using wait or waitpid (possibly from a SIGCHLD handler), or you could cause them to be automatically reaped using $SIG{CHLD} = 'IGNORE';. See perlipc.

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

Sidebar

Related Questions

As I have started using Linux (Ubuntu) to broaden my knowledge, but the flow
I am using Linux Mint 12, Kernel 3. I have installed and configured Open
I'm using linux. I have a function called like: PlayBackgroundIntroMusic((char *)IntroMusic); The functions is:
I'm using Linux Ubuntu Intrepid Ibex and using as compiler the gcc , but
I'm programming C using Linux gcc with -std=c89 switch. I have a variable storing
I've been using Linux for several years, but never stepped beyond installing from a
Ok, I have Netbeans 6.7.1 installed with the default Java SDK. I'm using Linux
am using Linux opensuse, eclipse helios package i have to import google maps in
I am trying to transfer an image using TCP sockets using linux. I have
using linux commands, I have a quoted csv file which I sorted by first

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.