How does hibernating an app work technically? I was wondering how hibernating of an app works technically.

I know about freezing an app (shell pm disable com.mypackage.name), 
but this also hides the app icon from launcher. I want to know how Greenify App works. It disables the app from running in background until I launch it again and then when I exit from that app, Greenify automatically hibernates it. 

So my question is how does it do that?
This is a citation from excellent explanation by lioux on XDA:

Greenify uses the Android command am to stop an app and applies this command again if the app is awakened by any action whatsoever. That's what hibernating means. Hibernated app will no longer start during phone boot, respond to registered intents or be triggered by alarms from the system. Everything it does is temporary. The am command does not touch the installed files or any configuration information.