delphi programming forums mysql charset mget recursive synonimos
free ventrilo servers hosting cs javascript delay python find in list
Back Forum New
abstract:

2) Repeat the preceding exercise, this time using the CreateProcess () in the Win32 API. In this instance, you will need to specify a separate program to be invoked from CreateProcess(). It is this separate program that will run as a child process outputting the Fibonacci sequence. Perform necessary error checking to ensure that a non-negative number is passed on the command line.
i have done with Fibonacci sequence .but i dont know how to include tht fork() function and win32 api .any one can help to finish ?


he Fibonacci sequence is the series of numbers 0, 1, 1, 2, 3, 5, 8, .... Formally, it can be expressed as:
f ib0 = 0
f ib1 = 1
f ibn = f ibn−1 + f ibn−2
1) Write a C program using the fork() system call that that generates the Fibonacci sequence in the child process. The number of the sequence will be provided in the command line. For example, if 5 is provided, the first five numbers in the Fibonacci sequence will be output by the child process. Because the parent and child processes have their own copies of the data, it will be necessary for the child to output the sequence. Have the parent invoke the wait() call to wait for the child process to complete before exiting the program. Perform necessary error checking to ensure that a non-negative number is passed on the command line.
2) Repeat the preceding exercise, this time using the CreateProcess () in the Win32 API. In this instance, you will need to specify a separate program to be invoked from CreateProcess(). It is this separate program that will run as a child process outputting the Fibonacci sequence. Perform necessary error checking to ensure that a non-negative number is passed on the command line.
i have done with Fibonacci sequence .but i dont know how to include tht fork() function and win32 api .any one can help to finish ?

TOP

fork() is a UNIX/Linux system call.  To my knowledge, it is still not supported in Windows.
The Win32 CreateProcess() function is a Windows function.
Obviously, you will need to write and run the two programs on two different systems.  Was that part of your question?
Is the problem that you don't know what fork() does?  We really work a lot better when fed specific questions; it keeps us from having to play 20 Questions with you.
Try Google'ing on
man page fork
for more information on that function.
Or, you could read your textbook's explanation.
PS
OK, here's the skinny on fork().  It creates an exact clone of the current process -- except for the process ID (PID) and parent PID (PPID), of course -- starts that clone running starting at the fork() call, and then returns.  In both processes.  The only way the original process and the clone (AKA "parent and child", respectively) can tell which one they are is from the return value of fork().
So, you assign the return value of fork() to a variable (the parent will need it later) and then test its value in an if-else statement.  If the process is the child, then it will do one thing, but if it's the parent, then it will do something different.
Usually, the child will perform whatever special task -- there's an extremely common procedure in UNIX system programming whereby the child replaces itself with an entirely different process, this being the way that one process spawns another, but you don't need to do that here.
And usually the parent will wait for the child to complete its task and terminate, which is what your assignment requires.  You'd want to read the man pages for wait() and waitpid().  Your assignment specifically tells you to use wait().
For CreateProcess, you'd want to use Google to find the Microsoft Developer's Network (MSDN) page on that function.
PPS
Could you please explain to us why you've been given an assignment that is specifically for giving you practice in spawning new processes in two different operating systems, and you don't have a single clue about spawning processes?

TOP

What compiler(s) are you using?



2) Repeat the preceding exercise, this time using the CreateProcess () in the Win32 API. In this instance, you will need to specify a separate program to be invoked from CreateProcess(). It is this separate program that will run as a child process outputting the Fibonacci sequence. Perform necessary error checking to ensure that a non-negative number is passed on the command line.
i have done with Fibonacci sequence .but i dont know how to include tht fork() function and win32 api .any one can help to finish ?

TOP

Back Forum