added debug option, struggle with pseuo terminal and hangup on mac os x