LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-22-2008, 07:09 AM   #1
saanchi
LQ Newbie
 
Registered: Nov 2007
Posts: 2

Rep: Reputation: 0
Create a zombie that exists even after parent dies.........


I want to create a zombie process that exists even after parent dies. But the problem is that as soon as the parent dies init adopts the zombie process and so it do not exists . could anyone suggest some method that could make me write a c program that enable me see a zombie process after parent exits..............
 
Old 02-22-2008, 08:30 AM   #2
cicorino
Member
 
Registered: May 2006
Location: Italy
Distribution: Slackware, Slackware64
Posts: 31

Rep: Reputation: 16
I'm not expert, anyway maybe you're trying to fake what the 'nohup' does, so I think that you just need to write a signal handler that ignores SIGHUP inside the code of your zombie...or you can use system( "nohup yourZombieExecutable") to run it from the parent.
 
Old 02-22-2008, 09:26 AM   #3
Telemachos
Member
 
Registered: May 2007
Distribution: Debian
Posts: 754

Rep: Reputation: 60
I can't answer your question, but I have to say it's on my all-time list of great titles for a post.
 
Old 02-22-2008, 10:29 AM   #4
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Don't have anything useful either, but if you do figure it out I suggest calling the keeper if the zombies a "Zombie Monger."
ta0kira
 
Old 02-22-2008, 11:07 AM   #5
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Yes, you will have to ignore SIGHUP and probably close the standard file descriptors. Take a look at man 3 daemon.
 
Old 02-22-2008, 01:46 PM   #6
saanchi
LQ Newbie
 
Registered: Nov 2007
Posts: 2

Original Poster
Rep: Reputation: 0
ignoring SIGHUP didn't help............it is still being adopted by init ...is there any method by which i could change the parent of any process?
 
Old 02-22-2008, 02:09 PM   #7
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Quote:
Originally Posted by saanchi View Post
ignoring SIGHUP didn't help............it is still being adopted by init
I thought the goal was to have init (or whatever process is the parent’s parent) adopt the process in question (and the process itself not having exited).

Init will (or should) always wait for the adopted children, so you will never have a “zombie” process which is the child of init (i.e., if the process has already exited, and was previously a zombie since its parent was not waiting for it, and its parent dies, then the zombie will die as well). That’s one of the purposes of init.
 
Old 02-22-2008, 04:30 PM   #8
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
What will the zombie do for you (labor, eating people)? Are you just looking for its exit info? Are these plain forks, or are they forks with execvs? If they're execvs then you could just use a wrapper program that re-forks, execvs, then waitpids and exports the exit info. The wrapper process will stick around even after the parent exits, thereby preserving the defunct process in the table if you want it to wait a long time before the waitpid.
ta0kira

PS Even if it doesn't execv, you can still add an additional fork that does the waitpid after a lengthy delay.

Last edited by ta0kira; 02-22-2008 at 04:34 PM.
 
Old 02-23-2008, 06:10 AM   #9
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
I thought that if you end a comand with ampersand, it gets detached from he parent. Isn't that all you really need to do?

Through a C program, I would simply "system or exec or some equivalent".

End
 
Old 02-23-2008, 02:47 PM   #10
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
No, & gives you a process group that doesn't have control of the terminal through tcsetpgrp. It still belongs to the parent unless it calls setsid (normally requires an additional fork if the parent is the shell.) You need setsid to break away from the parent, which can be done using the setsid shell command or system call. When you fg a process, all that does is have the shell give it terminal control with tcsetpgrp.
ta0kira
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to identify a zombie process and control it after parent dies vijaya_svk Programming 1 01-21-2008 04:44 AM
Bash child process in foreground while parent dies kborgnis Programming 3 11-09-2007 06:50 AM
getenv("LOGNAME") is incorrect when a child create a shell which call parent powah Programming 3 08-23-2007 12:29 AM
TCL/expect - parent hangs when child dies Hewson Programming 1 03-27-2007 08:44 PM
SIOCADDRT: File exists SIOCCADDRT: File Exists Failed to bring up eth0. opsraja Linux - Networking 0 01-10-2005 08:29 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration