Why does a system call crashes on second iteration of cycle while succeed on first? I faced this problem in the below C++ program