What's the output from this program using fork() and why?

Let’s learn what's the output from this program using fork() and why. The most accurate or helpful solution is served by Stack Overflow.

There are ten answers to this question.

Best solution

Why does this program using fork() and wait() output 201 when I run it?

When I diagrammed this, I wrote that the possible outputs could be 3020140, 1203040, 2013040, 1302040, or 3012040. When I ran it, the output was 201. What's going on? How could the program never reach 3, and what's happening with the wait condition? I thought wait meant that that calling process would not continue until children processes had finished, meaning that it would always be at the end of output. int main() { if (fork() != 0) { if (fork() == 0) { printf("3"); } else { pid_t pid...

Answer:

One observation: the complete lack of newlines in the print statements means that the output is only...

Read more

Anderson Cook at Stack Overflow Mark as irrelevant Undo

Other solutions

C++ program using visual c++. Functions, call and ref statements with for loops, output two separate tabless?

Need a little help please: i have been trying to complete this for a couple days but i get more and more confused everytime i try. When an object is falling because of gravity, the following formula can be used to determine the distance the object falls...

Answer:

Both functions are wrong because you are supposed to pass the time and return the distance which you...

Read more

e at Yahoo! Answers Mark as irrelevant Undo

Unix: How exactly does the time command work? And why a program could fail (only) when launched with it?

I am launching a benchmark (DaCapo java benchmarks) with the time command prepended on a Unix platform (Ubuntu). The same command does not fail when launched without a time command but it randomly fails (80% of the times) when time is invoked. Parameters...

Answer:

Short answer:  read the source code to find out. Index of /debian/pool/main/t/time Or, maybe strace...

Read more

Paul Reiber at Quora Mark as irrelevant Undo

Whats wrong with my Class in C++?

Im trying to use everything ive learned so far into a conversion program, meaning im trying to use: classes, functions, return, user input, and over all a working program. But im coming across an error and im fairly new to C++, so some guidance would...

Answer:

2 problems: 1. Your ConversionFunct() function is supposed to return an integer, but doesn't have any...

Read more

Kira L. at Yahoo! Answers Mark as irrelevant Undo

Whats wrong with my code C++. The question follows.?

The main function of the incomplete program below initialises the variables name, addr1, addr2 and postalCode and then calls function displayData to display the name and address as follows: Mr R.S. Bopape P.O. Box 50741 Sandton 2146 Your task is to write...

Answer:

The only real problem I see is that the type declaration for "postalCodeP" is "sring...

Read more

Timothy C at Yahoo! Answers Mark as irrelevant Undo

Help using fork() in C programming?

Here's two pieces of my program. The first one for normal order works fine. I need help making it so I can reverse the order of the output. In normal order the original process ...show more

Answer:

i can't understand what u mean. you can't start from a child... first comes the father, then the child...

Read more

JQPN44SNSOEXHC223JA5N3IEQI at Yahoo! Answers Mark as irrelevant Undo

File I/O C++ help plzz?

This is just a partial of the code but can anyone help me with CASE 2(calculating the sum)? I keep getting wrong output. Is there something I should add/remove or did I need to do something about the entire code? #include <iostream> #include <...

Answer:

Probably you have tried first option 1 and then option 2. If you would have tried option2 first time...

Read more

James Bond at Yahoo! Answers Mark as irrelevant Undo

Game Console Video Capture, Maybe a different question then the usual?

I've been reading up and watching vids on Capturing video from game consoles, I had a different question though. My PC monitor has an HDMI Input on it. I have a PS3 with HDMI Output. Is there a program that will or can switch or view the other components...

Answer:

i had this exact question... some people seem to be able to use a hypercam type thing....

Read more

naydog10... at Yahoo! Answers Mark as irrelevant Undo

Interrupting itunes playback - how to do it automagically

I want to interrupt a playing itunes stream with another program's output. I already have many pieces in place, but I need to trigger itunes to shaddap. How to do? My client is a coffee shop and has a large Muslim following. We want to have call to prayer...

Answer:

Are there WMI events I could trap, and whats the best way to go about using them? Does a window pop...

Read more

disclaimer at Ask.Metafilter.Com Mark as irrelevant Undo

Why does a program's output file go from 0 bytes to 32 MB without any intermediate size (writes all at once?)?

I wrote a program to split up a database into 30 pieces and run a program called RNAfold to analyze the data from each piece separately. For each piece there is one output file. Then I stitch up the output files in one file again. The problem is I can...

Answer:

Because the program that is writing to the file has it locked. Windows, or your OS, cannot do anything...

Read more

Chris G at Yahoo! Answers Mark as irrelevant Undo

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.