Skip to content

Better document that process::exit does not result in a clean shutdown #28058

Closed

Description

@crumblingstatue

The documentation states If a clean shutdown is needed it is recommended to only call this function at a known point where there are no more destructors left to run., however simply running it when no more destructors are left to run does not guarantee a clean exit. For example, output buffers are not flushed, as opposed to normal program termination. There might be other things that process::exit does not do that normal program termination does that I'm not aware of. These too should be documented. Or at the least, the documentation should not imply that if you run process::exit when there are no more destructors left to run, you get a clean exit.

Furthermore, process::exit should not be recommended as a mechanism for simply setting the exit code. env::set_exit_status was deprecated with the message Deprecated since 1.2.0: use process::exit instead, then removed. process::exit is simply not a good alternative. There are valid reasons for setting the exit code without abormal program termination.

Examples:

  • Incorrect command line argument: Print help, set exit status to non-zero. Clean exit.
  • File stated in command line argument does not exist. State this to the user, set exit status to non-zero. Clean exit.

Activity

  1. changed the title [-]Better document lack of clean shutdown with process::exit[/-] [+]Better document that process::exit does not result in a clean shutdown[/+] on Aug 28, 2015
  2. sfackler commented on Aug 28, 2015

    @sfackler
    Member

    Which output buffers are not flushed? We register atexit handlers to take care of the global stdout buffer: https://github.com/rust-lang/rust/blob/master/src/libstd/io/lazy.rs#L53, and stderr is unbuffered.

  3. crumblingstatue commented on Aug 28, 2015

    @crumblingstatue
    ContributorAuthor

    Which output buffers are not flushed? We register atexit handlers to take care of the global stdout buffer: https://github.com/rust-lang/rust/blob/master/src/libstd/io/lazy.rs#L53, and stderr is unbuffered.

    fn main() { print!("Hi!"); } results in "Hi!", fn main() { print!("Hi!"); std::process::exit(0); } results in no output.

  4. sfackler commented on Aug 28, 2015

    @sfackler
    Member

    That seems like a bug in rt::atexit: #28065

  5. steveklabnik commented on Sep 4, 2015

    @steveklabnik
    Contributor

    Given that the bug has been fixed, I'm going to give this a close. Please let me know if that's still wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions