Thanks for your help everyone, I figured it out. The cause of the problem seems to be unrelated to the F_SETFL- it just happened to seg fault at that point all the time. Cheers, Daniel