Sometimes I accidentally killed all the background jobs in a shell, for example, because The window of a Window's program running under Wine is not in the front by default.
I know I can use
disown to protect them from being killed when killing the shell or its terminal emulator process. But if my OS is frozen, I have to restart the OS, and neither
disown can save any background process.
Is there a way to log the commands of the background jobs that are running in a shell process or all the shell processes (those manually started in particular), either periodically, or manually?
What I am thinking is to write a script, which is executed periodically in all the shell processes, and for each shell process, it will simply append the stdout output of
jobs to a shared text file.
But I am not sure how to make it go through all the shell processes, and how to reduce any duplicate commands. I would like to log the commands in a way that I can execute the log file directly as a shell script to rerun the commands