BUGFIX: use truncate inshead of ftruncate (which not exist)
BUGFIX: Properly close filehandle if process run.