How to run terminal commands when terminal itself isn't responding?
No. When you’ve gotten a system in extreme and memory is fully committed, your only home is to ssh in remotely or get lucky with an app launch. 

You might need to just power off the machine and pick up the pieces of lost and unsaved data as needed. 

Unless you have the shell already open, chances of spawning a new one are slim. 

Force quitting any non needed apps might also get you a narrow window to resume control.