Skip to content
Advertisement

Irregular result in zombie example

I have problems with understanding the behavior of this code:

JavaScript

When running in a Unix shell I get this result:

JavaScript

But sometimes its only giving me this result without any shell prompt:

JavaScript

I know it can be solved with wait() function in parent process. But I like to know:

Why is result irregular? Could someone please explain what happening? Child process becomes a zombie, but why do not parents process printf() function call run?

Advertisement

Answer

There are 2 issuse to concider: 1) there is stdout buffering that you might want to flush

JavaScript

2) multitasking can sometimes execute the stuff in an unexpected order I get something like this when that happens:

JavaScript

as you can see the prompt is in the beginning of the child process output, it’s not missing altogether it’s just not where you expect it to be.

With this code I tried several times bit never had the prompt in teh output lines of the child or parent:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement