GithubHelp home page GithubHelp logo

fork-onacci's Introduction

Fork-onacci

Having fun with fork! Or at least burning some cycles.

Today, we're going back to 1112, and mastering recursion. Remember good 'ol fibonacci:

fib(0) = 0
fib(1) = 1
fib(n) = fib(n - 1) + fib(n - 2)

If it is good enough for the golden ratio, it's good enough for a class exercise!

Task 1

Implement fib in C. I know, real hard.

Task 2

Use fork, exit, and wait to calculate fib...fibork! Each recursive "call" to fibork should be in a new process. You should not use fib in your implementation, and each call to fibork should result in creating two children processes, each of which call fibork for the recursive call. You'll have to think about how fork works to figure out how to pass the argument. To "return", you'll need to exit, and to pass the return value, the exit value will need to percolate to wait. Note that when wait(&status) gets the status from exit, you must use WEXITSTATUS(status) to access its value.

You can use man to figure out how to use these calls appropriately.

Task 3

Change the optimization settings from -O0 to -O3, and recompile (make sure to run make clean). Form a hypothesis:

  • What will happen to the performance of each implementation?
  • How much will they improve?

Then execute the system. Does it match your hypothesis? Why or why not?

Task 4

Remember our old friend, objdump? Lets figure out why the performance changed? Use objdump -S and look at your function's implementation. If you want to more easily search through objdump's output, you might consider outputting to a file (e.g., objdump -S bin > output.txt). What made it faster?

fork-onacci's People

Contributors

gparmer avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.