solution for question in APUE(Advanced Programming in the UNIX Enviroment)