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, and then another child of child and so on... if you want to reverse the order, you should store output using e.g. a list (beware of concurrency! you may need locking the data structure) ~ a list, simply struct anode { struct anode *next; char memstring[256]; // limited output length }; but you can also do something simpler: char *list[ MAX_NUM_OF_CHILDREN ]; MAX_NUM_OF... maybe is the same as depth. then you don't write out the output, you store it; something like list[c] = malloc(MAX_STR_LEN); // add a check snprintf(list[c], MAX_STR_LEN, "process %d .. %d\n", getpid(), getppid() ); and at the end you do a for(c=depth-1;c>=0;c--) { printf("%s", list[c]); free(list[c]); } to print the outputs in reverse order not sure it works, ...
JQPN44SNSOEXHC223JA5N3IEQI at Yahoo! Answers Visit the source
Related Q & A:
- How to do Network discovery using UDP Broadcast C#?Best solution by Stack Overflow
- What are some basic c++ programming techniques?Best solution by Quora
- What certification can I get for C Programming?Best solution by Yahoo! Answers
- How hard is C++ programming?Best solution by Yahoo! Answers
- Can anyone help me with this C++ program?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.