3
srpatil
53d

I came across this code snippet on Quora, and I tried crashing the Codeforces server (strictly for educational purposes). But this thing wouldn’t compile, either because fork() was not declared in the scope, or the file <unistd.h> was not found. I tried it on different C++ machines. What is the fix for this ?

Comments
  • 3
    Try compiling with a C compiler instead. I don't know if unistd.h is available in C++.
  • 1
    Doesn't compile, no instructions? Definitely quora.
  • 3
    It's not a c++ thing, c++ compilers work with C just fine (you may need to specify linkage properly). Maybe they don't include unistd.h in the compiler include list for precisely this reason. After all why would competitive programming code need access to Unix systems libraries?

    Also, it's probably not going to do anything to the server. If Codeforces is run by even marginally competent people they'd limit the number of processes that your process can spawn and just timeout your program after a while (using ulimit etc) (also after all why would a competitive program need to fork anyway?)
  • 1
    You could look up unistd.h on your dev machine, extract the relevant function prototypes and put them into your file. Then it will compile. Linkage may be the next problem though.
  • 1
    Shell command execution via a single string parameter function. Oh man I don't like unix
  • 0
    Maybe you're on Windows...
Add Comment