Use nanosleep() to implement sleep()