code from book "Understanding Unix/Linux Programming".