Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > parent of an orphaned process

Reply
Thread Tools

parent of an orphaned process

 
 
madhav_a_kelkar@hotmail.com
Guest
Posts: n/a
 
      11-24-2004
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.
 
Reply With Quote
 
 
 
 
Anno Siegel
Guest
Posts: n/a
 
      11-24-2004
<> 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
 
Reply With Quote
 
 
 
 
madhav_a_kelkar@hotmail.com
Guest
Posts: n/a
 
      11-25-2004
(Anno Siegel) wrote in message news:<co1nur$5ea$>...
> <> 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.
 
Reply With Quote
 
Darren Dunham
Guest
Posts: n/a
 
      12-01-2004
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. >
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding Orphaned Files On A Website newspost2000 HTML 10 01-03-2013 12:03 PM
If a class Child inherits from Parent, how to implementChild.some_method if Parent.some_method() returns Parent instance ? metal Python 8 10-30-2009 10:31 AM
Link validation and finding orphaned files newspost2000@yahoo.com HTML 0 02-07-2006 09:15 PM
parent of an orphaned process-info about perl and OS version. madhav_a_kelkar@hotmail.com Perl Misc 5 12-02-2004 11:54 PM
Orphaned Excel 97 Instances (C#) rhett ASP .Net 0 12-02-2004 06:25 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57