title: Interruptible in-place sorting algorithm
body: <p>I need to write a sorting program in C and it would be nice if the file could be sorted in place to save disk space. The data is valuable, so I need to ensure that if the process is interrupted (ctrl-c) the file is not corrupted. I can guarantee the power cord on the machine will not be yanked. </p>
  
  <p>Extra details: file is ~40GB, records are 128-bit, machine is 64-bit, OS is POSIX</p>
  
  <p>Any hints on accomplishing this, or notes in general?</p>
  
  <p>Thanks!</p>
  
  <p><strong>To clarify:</strong> I expect the user will want to ctrl-c the process. In this case, I want to exit gracefully and ensure that the data is safe. So this question is about handling interrupts and choosing a sort algorithm that can wrap up quickly if requested.</p>
  
  <p><strong>Following up (2 years later):</strong> Just for posterity, I have installed the SIGINT handler and it worked great. This does not protect me against power failure, but that is a risk I can handle. Code at <a href="https://code.google.com/p/pawnsbfs/source/browse/trunk/hsort.c" rel="nofollow noreferrer">https://code.google.com/p/pawnsbfs/source/browse/trunk/hsort.c</a> and <a href="https://code.google.com/p/pawnsbfs/source/browse/trunk/qsort.c" rel="nofollow noreferrer">https://code.google.com/p/pawnsbfs/source/browse/trunk/qsort.c</a></p>