Question

A program may first issues an asynchronous I/O operation with aio_read() or aio_write() and then call exit() to terminate itself.

...
aio_write(aiocbp);
exit(0);

My question is, will the exit() call wait until the async i/o is done or the program will directly terminate?

Was it helpful?

Solution

I believe the relevant language in the standard is:

Consequences of Process Termination

All of the file descriptors, directory streams, conversion descriptors, and message catalog descriptors open in the calling process shall be closed.

Source: http://pubs.opengroup.org/onlinepubs/9699919799/functions/_Exit.html

and:

When there is an outstanding cancelable asynchronous I/O operation against fildes when close() is called, that I/O operation may be canceled. An I/O operation that is not canceled completes as if the close() operation had not yet occurred. All operations that are not canceled shall complete as if the close() blocked until the operations completed. The close() operation itself need not block awaiting such I/O completion. Whether any I/O operation is canceled, and which I/O operation may be canceled upon close(), is implementation-defined.

Source: http://pubs.opengroup.org/onlinepubs/9699919799/functions/close.html

So, it's unspecified; either the unfinished operations are cancelled, or the operation blocks until they finish.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top