Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: I got zombies

by BlaisePascal (Monk)
on Aug 08, 2000 at 03:48 UTC ( [id://26700]=note: print w/replies, xml ) Need Help??


in reply to I got zombies

It doesn't sound like zombies to me.. Zombies die before their parents, not the otherway around.

If I understand you, you are doing something like this:

if (!fork()) { setsid() exit if fork(); ...do child stuff } else {...do parent stuff}
(Note: I can't find any perl documentation on setsid, where am I not looking?)

According to Stevens (Advanced Programming in the UNIX Environment) that is basically the standard recipe for creating a detached process -- one in it's own session and process group. And since the child's real parent is dead, it was inherited by init (process 1).

So if that is what you are doing, then you are doing exactly the wrong thing to do if you want the child to die when the parent does.

If you want the background process to terminate when the foreground process terminates cleanly (i.e., not from "kill -9"), you could use a flag set by parent when shutting that is shared between processes, or or pass the child's PID to the parent (through shared memory) and send a signal from the exiting parent. If you wanted a SIGINT or SIGKILL to go to both processes, you could use setpgrp() to place the background process in the same process group as the parent (but you can do the same thing by not using setsid).

Why are you using setsid() in the first place?

Replies are listed 'Best First'.
RE: Re: I got zombies
by tilly (Archbishop) on Aug 08, 2000 at 04:44 UTC
    Where you were not looking was the POSIX module. That is where setsid() is defined.

    EDIT
    I went and read it closely. Actually it isn't defined there. It just tells you to see your man page.

    DESCRIPTION
    setsid() creates a new session if the calling process is not a process group leader. The calling process is the leader of the new session, the process group leader of the new process group, and has no controlling tty. The pro­ cess group ID and session ID of the calling process are set to the PID of the calling process. The calling pro­ cess will be the only process in this new process group and in this new session.
    The usage in the code is absolutely identical to what my man page (Debian) has to say in its notes about this function.

    BTW I have been amazed lately at how good Google is for picking up information on random technical things. For instance here is a search on setsid.

RE: Re: I got zombies
by reptile (Monk) on Aug 08, 2000 at 05:53 UTC

    There is no foreground process. It's using setsid() to disassociate the child from the parent, then the parent exits. The remaining process (the child) forks a process it's the parent of and they both do their own thing.

    I should have just left out the setsid() because you're apparently confused by what I intended to do with it. I wasn't sure if it was pretinent or not, so I mentioned it.

    I'm doing something like this:

    use POSIX qw/setsid/; if ( fork() ) { exit; } else { setsid(); } # now the foreground process is gone and I'm the child if ( fork() ) { &do_something(); } else { &do_something_else(); }

    They both stay around in an infinite loop doing whatever they're supposed to do. I have to kill them both or whichever one I don't kill sticks around. Like from ps auxf:

    iniquity 26464 0.5 15.9 2976 2348 ? S 21:41 0:00 perl -w ./si +ncd.pl iniquity 26465 0.0 15.4 2920 2276 ? S 21:41 0:00 \_ perl -w +./sincd.p

    If I kill 26464, 26465 doesn't go away.

    local $_ = "0A72656B636148206C72655020726568746F6E41207473754A"; while(s/..$//) { print chr(hex($&)) }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://26700]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-04-24 01:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found