|OSX 10.10.5] Script execution stops when screen locked? I was running a script that takes ages in Terminal.

I wanted to run it unsupervised while I was working away from my MacBook, so I chose from the menu (top right) username > Login Window..., which is NOT logout, but the lock screen.

I was expecting the script to run. When I returned hours later and unlocked the screen (by typing in my password), I had to find out that while the screen was locked the script was paused all the time, and just continued where it set off when I unlocked the screen.

The expected behaviour (known from other UNIX derivatives) would have been to run while the UI was locked and secure.

How can I achieve this?
EDIT: With macOS High Sierra (as of beta 5) you can achieve the same "lock screen" behaviour mentioned by @Phong simply through the  status bar menu:





What I think is happening is that your computer goes to sleep after a certain amount of time after you switched to the login window which causes your script to stop.

To prevent your system from sleeping while your script is running you can run caffeinate -s in Terminal (note: only works on MacBooks if AC power is connected) or include it in your script. To stop the command hit CTRL+C.

The way I go about securing my account while I'm still logged in is to enable the "require password" option in system preferences:



Then, as soon as the display (not the system) goes to sleep (also configurable in preferences) you have to enter a password in order to access the account.

You can also manually trigger display sleep by hitting CTRL+SHIFT+EJECT (if your keyboard has an eject button) or by running pmset displaysleepnow.