zombie to exist after the termination of main program..


 
Thread Tools Search this Thread
Top Forums Programming zombie to exist after the termination of main program..
# 1  
Old 02-22-2008
zombie to exist after the termination of main program..

main()
{
pid_t child;
child=fork();

if(child > 0)

{sleep(60);
}

else
{exit(0);
}

}

the above code will create zombie process,which will be adopted by init as soon as parent process will dies.Can any one gimme a code or an alogrithm to keep this zombie proocess alive even after its parent dies...i.e to stop init from adopting it after the termination of main programme
# 2  
Old 02-24-2008
Fork again. Keep the child process running. When the original process exits, the child process will keep the grandchild process in a zombie state when it exits.

Otherwise no, there's no way to keep an orphan process from being adopted by init.
# 3  
Old 02-24-2008
thanx for ur reply sir , i had already done my assignment with this logic....Smilie
but i think the child process was supposed to stay as zombie after the termination of main program not its grandchild......Smilie
this is possible through kerenl level programming....
# 4  
Old 02-24-2008
Why on Earth would anyone want a zombie to persist like this? The zombie's only purpose is perserve the exit code of the process so that the parent can obtain it. Once the parent is dead, there is no purpose left for the zombie. If you disable the reaping of zombies on a systemwide basis, the process table will fill and you will be unable to fork new processes. If that is your goal, you can easily fill the process table with living processes rather than zombies. Just write a "while(1) fork();" program and run it as root. Fair warning: it will be rather hard to recover from that and you may need to cycle power to the system. If you must fill the process table with zombies you will need to rewrite init to not reap zombies. There will be no way to recover from that. You will need to recycle power each time the process table fills. If you modify init to not reap only a few certain zombies, you will be able to use the system for a longer period before the process table fills.

I would really like to hear an explanation as why someone wants unreapable zombies. Is any benefit expected from an unreapable zombie?
# 5  
Old 02-25-2008
thanx for ur explanations.....!!
i m not interested in making zombies unreapable..all i wanted to hav an idea that whether its possible or not to do it...

If u look at the code above in first post,i hav made parent process to sleep for 60secs
If i run this code(i.e ./a.out) n then execute "ps -eaf" on the terminal within 60secs... i will see
1)./a.out
2)[a.out <defunct>]

If i again execute "ps -eaf" after 60secs i wont see those two output....
bcoz its no longer exist ,after 60secs the main program has terminated and [a.out <defunct>] has been adopted by init .

i want these two output to remain there even after the parent process has terminated i.e if i run "ps -eaf " after 60secs the same output should be seen ..

actually this is my lab assignment questions which goes as follow

"Write a Unix program that will create a zombie process that exists after
the main program terminates.
"
so in order to solve this i was seeking help in different forums..
# 6  
Old 02-26-2008
This is an example why Homework is not allowed on the Forums. Apparently nobody here could figure out why any sane person would do that.

Do not post homework questions.
# 7  
Old 02-27-2008
Do not post homework questions. Closing the thread.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Could not find the main class: Grasp. Program will exit.

I am having trouble running jgrasp. I get the message above when I try to run jgrasp. I am running fedora if that makes a difference. I have already set my environmental variable with this. Hopefully I did it right. JGRASP_HOME=/opt/jgrasp export... (0 Replies)
Discussion started by: cokedude
0 Replies

2. AIX

Calling functions from main program from dlopened library function

Hello All, I am trying to call a function from the calling main program from a dlopened library function, below is the entire code, when I execute it it crashes with sigill. Can you guys help me out I guess I am missing out on the linker flag or something here. besides I am new to AIX and... (1 Reply)
Discussion started by: syedtoah
1 Replies

3. AIX

Help with AIX XL C++ complier: app exit before main program

I have two shared libraries, A, B(B depents on A, both linked with -G option which means they're rtl enable), B's toc size is bigger than 64K(-bbigtoc), while A's toc size smaller than 64K. Then I write a "Hello, world" example E, and link with A and B. Link cmd 1: xlC128_r -o E E.o -lA -lB... (0 Replies)
Discussion started by: jackliang
0 Replies

4. Shell Programming and Scripting

main program is not calling small other programs

I am trying to understand a program in a book and this program suppose to call other programs which are in the same folder, the other programs are called 'lu' and 'add' but for some reason when it gets to the last line of each case to call these programs there is an error message saying ./rolo:... (2 Replies)
Discussion started by: bartsimpsong
2 Replies

5. Shell Programming and Scripting

To see if a program exist and is executable

Hi, I am making a program that needs to detect if the program name in parameter is a valid runable program. But the line if ; then never seem to work. Even if I run like: ./script cat "-u" cat "-u" inputfile Thank you everyone. #!/bin/bash # usage() { #print usage message and quit... (4 Replies)
Discussion started by: leonmerc
4 Replies

6. Shell Programming and Scripting

Problem with ssh termination...

hi all, i have a situation where i run ssh command from a unix machine to execute few scripts on 2 other unix machines. my problem is, the scripts that i run will start few commands on the 2 servers and will quit....i am able to quit from the script but i have to give ctrl+c (on the... (10 Replies)
Discussion started by: niteesh_!7
10 Replies

7. Red Hat

Zombie Process Termination Time

Hey, I've got a program that fork's a list of child processes, and keeps their pid's in a list. After the parent finishes it's main business logic, it needs to check which child already finished - and when. Is it possible - using waitpid or any other func\syscall - get this information... (0 Replies)
Discussion started by: sternr
0 Replies

8. Shell Programming and Scripting

zombie processes and hung process termination

Is there a way I can run a command that will run in the kernel or in the memory and automatically kill certain scripts if they get to <defunct> processes, without having to be monitoring the server manually? I have a Perl script which runs for 20k members and normally does not have any problems,... (2 Replies)
Discussion started by: ukndoit
2 Replies

9. UNIX for Dummies Questions & Answers

zombie program

When you run a ps -ef and if the status is a Z (zombie) does that mean the same as not responding? (Like a windows machine). Also has anyone here heard of the program called 'top' (I've found it on our Solaris 7 machines) If you have you might be able to help me. I need to know if there is a... (8 Replies)
Discussion started by: merlin
8 Replies

10. UNIX for Dummies Questions & Answers

Abnormal Termination errors

I'm having trouble with Abnormal Termination errors. What are they, what causes them and how can I prevent them from happening? Are they application specific? (2 Replies)
Discussion started by: bialsibub
2 Replies
Login or Register to Ask a Question