> For the complete documentation index, see [llms.txt](https://sec88.0x88.online/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sec88.0x88.online/programming/go/signals-exit.md).

# Signals-Exit

### Exit

* to exit the app we can use `os.Exit(0)`
* <http://tldp.org/LDP/abs/html/exitcodes.html>

```go
defer fmt.Println("bye")
// code zero indicates success, non-zero an error.
// defer will not run
os.Exit(9)
```

### Signals

* Notify causes package signal to relay incoming signals to "sigs".
* If no signals are provided, all incoming signals will be relayed to "sigs".
* Otherwise, just the provided signals will.

```go
{
	// channel that we will get signals on it
	sigs := make(chan os.Signal)
	// channel that we will use to shutdown the app
	done := make(chan bool)
	signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

	go func() {
		// blocking till we get os.Signal
		<-sigs
		// release resources
		// call shutdwon functions for HTTP server,  DB ...
		fmt.Println("\nDoing graceful shutdown")
		// send message to shutdown
		done <- true
	}()

	fmt.Println("waiting for os.Signal")
	// waiting internal shutdown message
	<-done
	fmt.Println("Exit")
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sec88.0x88.online/programming/go/signals-exit.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
