parent of an orphaned process

Discussion in 'Perl Misc' started by madhav_a_kelkar@hotmail.com, Nov 24, 2004.

  1. Guest

    hi all,

    i was doing the following program in perl

    #!/usr/bin/perl
    2
    3 main();
    4
    5 sub main
    6 {
    7 my $id;
    8 if(($id=fork())==0)
    9 {
    10 print("in child process, id=$$!\n");
    11 sleep 5;
    12 $i=getppid;
    13
    14
    15 if(kill 0,$i)
    16 {
    17 print("signal sent\n");
    18 }
    19 else
    20 {
    21 print("parent died pid=$i\n");
    22 }
    23
    24 exit;
    25 }
    26 else{
    27 print("parent terminated\n");
    28 exit(0);
    29 }

    note that i am taking the parent pid after the
    parent has exited. according to std unix idiom, the init process (with
    pid =1) should be the parent of the orphaned child process in this
    example. but when i executed the code, this was the output:

    [madhav@madhav perl]$ perl child.pl
    in child process, id=13235!
    parent terminated
    [madhav@madhav perl]$ parent died pid=13234

    this indicates that the parent of the orphaned child process is not
    the init process as it should be. please tell me what is means. i did
    the same program in C and got the parent id as 1. cant it be the same
    with perl?

    regards,
    Madhav.
     
    , Nov 24, 2004
    #1
    1. Advertising

  2. Anno Siegel Guest

    <> wrote in comp.lang.perl.misc:
    > hi all,
    >
    > i was doing the following program in perl
    >
    > #!/usr/bin/perl
    > 2
    > 3 main();
    > 4
    > 5 sub main
    > 6 {
    > 7 my $id;
    > 8 if(($id=fork())==0)
    > 9 {
    > 10 print("in child process, id=$$!\n");
    > 11 sleep 5;
    > 12 $i=getppid;
    > 13
    > 14
    > 15 if(kill 0,$i)
    > 16 {
    > 17 print("signal sent\n");
    > 18 }
    > 19 else
    > 20 {
    > 21 print("parent died pid=$i\n");
    > 22 }
    > 23
    > 24 exit;
    > 25 }
    > 26 else{
    > 27 print("parent terminated\n");
    > 28 exit(0);
    > 29 }
    >
    > note that i am taking the parent pid after the
    > parent has exited.


    You are taking it after sleeping for five seconds. Presumably the parent
    process had time to terminate, but we don't *know* this.

    > according to std unix idiom,


    Idioms are part of languages (including computer languages). What
    you are describing is the behavior of an OS, not an idiom.

    > the init process (with
    > pid =1) should be the parent of the orphaned child process in this
    > example. but when i executed the code, this was the output:
    >
    > [madhav@madhav perl]$ perl child.pl
    > in child process, id=13235!
    > parent terminated
    > [madhav@madhav perl]$ parent died pid=13234
    >
    > this indicates that the parent of the orphaned child process is not
    > the init process as it should be. please tell me what is means. i did
    > the same program in C and got the parent id as 1. cant it be the same
    > with perl?


    It is, for me. When I run your program, I see

    [anno4000@lublin ~/clpm]$ perl ttt
    parent terminated
    in child process, id=13690!
    [anno4000@lublin ~/clpm]$ parent died pid=1

    No idea why it's behaving differently for you, but it doesn't look
    like Perl is responsible.

    Anno
     
    Anno Siegel, Nov 24, 2004
    #2
    1. Advertising

  3. Guest

    -berlin.de (Anno Siegel) wrote in message news:<co1nur$5ea$-Berlin.DE>...
    > <> wrote in comp.lang.perl.misc:
    > > hi all,
    > >
    > > i was doing the following program in perl
    > >
    > > #!/usr/bin/perl
    > > 2
    > > 3 main();
    > > 4
    > > 5 sub main
    > > 6 {
    > > 7 my $id;
    > > 8 if(($id=fork())==0)
    > > 9 {
    > > 10 print("in child process, id=$$!\n");
    > > 11 sleep 5;
    > > 12 $i=getppid;
    > > 13
    > > 14
    > > 15 if(kill 0,$i)
    > > 16 {
    > > 17 print("signal sent\n");
    > > 18 }
    > > 19 else
    > > 20 {
    > > 21 print("parent died pid=$i\n");
    > > 22 }
    > > 23
    > > 24 exit;
    > > 25 }
    > > 26 else{
    > > 27 print("parent terminated\n");
    > > 28 exit(0);
    > > 29 }
    > >
    > > note that i am taking the parent pid after the
    > > parent has exited.

    >
    > You are taking it after sleeping for five seconds. Presumably the parent
    > process had time to terminate, but we don't *know* this.
    >
    > > according to std unix idiom,

    >
    > Idioms are part of languages (including computer languages). What
    > you are describing is the behavior of an OS, not an idiom.
    >
    > > the init process (with
    > > pid =1) should be the parent of the orphaned child process in this
    > > example. but when i executed the code, this was the output:
    > >
    > > [madhav@madhav perl]$ perl child.pl
    > > in child process, id=13235!
    > > parent terminated
    > > [madhav@madhav perl]$ parent died pid=13234
    > >
    > > this indicates that the parent of the orphaned child process is not
    > > the init process as it should be. please tell me what is means. i did
    > > the same program in C and got the parent id as 1. cant it be the same
    > > with perl?

    >
    > It is, for me. When I run your program, I see
    >
    > [anno4000@lublin ~/clpm]$ perl ttt
    > parent terminated
    > in child process, id=13690!
    > [anno4000@lublin ~/clpm]$ parent died pid=1
    >
    >


    *but it doesn't look like Perl is responsible.*

    i have checked the parent of the process by running the ps -ax command
    in another console while the child process was sleeping, and it is
    reporting me that the parent of this process is indeed the init
    process as it should be.
    this was the output when i checked it again:

    [madhav@madhav perl]$ perl child.pl
    in child process, id=4256!
    parent terminated
    [madhav@madhav perl]$ parent died pid=4255

    [root@madhav bin]# ps -lax | grep perl
    1 1104 4256 1 21 0 5308 1376 schedu S pts/0 0:00
    perl child.pl
    0 0 4258 2341 15 0 3572 624 pipe_w S pts/2 0:00
    grep perl

    this clearly shows that the init has clearly became the parent of the
    process.
     
    , Nov 25, 2004
    #3
  4. wrote:
    > hi all,


    > i was doing the following program in perl


    > #!/usr/bin/perl
    > 2
    > 3 main();
    > 4
    > 5 sub main
    > 6 {
    > 7 my $id;
    > 8 if(($id=fork())==0)
    > 9 {
    > 10 print("in child process, id=$$!\n");
    > 11 sleep 5;
    > 12 $i=getppid;


    What OS, what perl version, and was it built with threads?

    This used to not work under Linux and a threaded perl. I don't know if
    that has changed. getppid instead returned a value cached when the
    process was launched, not a value dynamically determined.

    --
    Darren Dunham
    Senior Technical Consultant TAOS http://www.taos.com/
    Got some Dr Pepper? San Francisco, CA bay area
    < This line left intentionally blank to confuse you. >
     
    Darren Dunham, Dec 1, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rhett

    Orphaned Excel 97 Instances (C#)

    rhett, Dec 2, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    2,079
    rhett
    Dec 2, 2004
  2. Replies:
    0
    Views:
    449
  3. newspost2000

    Finding Orphaned Files On A Website

    newspost2000, Feb 8, 2006, in forum: HTML
    Replies:
    10
    Views:
    7,587
  4. george1069 george1069

    Orphaned table-header help...

    george1069 george1069, Apr 3, 2005, in forum: XML
    Replies:
    0
    Views:
    425
    george1069 george1069
    Apr 3, 2005
  5. Replies:
    5
    Views:
    139
Loading...

Share This Page