If in sleep mode, your Mac closes all running programs and processes. Your computer might automatically log out after some period of inactivity. Here is how to change it:
Open System Preferences.
Go to the Security & Privacy section.
Click the Lock icon to make changes.
Click the Advanced button.
Disable the option to log out automatically.