If no desktop file could be found the only option left is taking the command found in /proc/{pid}/cmdline Save all the extracted metadata in a json file. The reason for considering /proc/{pid}/cmdline only as a last resort is that in my testing, just executing this is often a poor...
xsession-manager is a command line tool. It should fit your needs if you are running Gnome on X11. This extension probably can't be used in terminal directly. Maybe it can be used via D-Bus, I'm not sure about this. And I have been adding the feature of WIP: [Feature] Restore ...