A using the notation of the example in the text we

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ts the global variable errno to an error code that indicate the cause of the error. If wait completes successfully, then it returns the useful result, which is the PID of the reaped child. Unix-style error-handling code is typically of the form: 1 2 3 4 if ((pid = wait(NULL)) < 0) { fprintf(stderr, "wait error: %s\n", strerror(errno)); exit(0); } The strerror function returns a text description for a particular value of errno. Posix-style error handling Many of the newer Posix functions such as Pthreads use the return value only to indicate success (0) or failure (nonzero). Any useful results are returned in function arguments that are passed by reference. We refer to this approach as Posix-style error handling. For example, the Posix-style pthread create function indicates success or failure with its return value and returns the ID of the newly created thread (the useful result) by reference in its first argument. Posix-style error-handling code is typically of the form: 1 2 3 4 5 if ((retcode = pthread_create(&tid, NULL, thread, NULL)) != 0) {...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online