3

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 nohup or 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 nohup or 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

Thanks.

  • Won't always work: you could start a bash shell on the command line – Basile Starynkevitch Jan 12 '18 at 17:59
  • What kind of problem can it solve to start a bash shell in a shell? – Tim Jan 12 '18 at 18:02
  • It won't solve problems, but start new ones. The jobs inside the inner shell won't be logged. My comment is that your goal is not achievable in general, even if you could sometimes find a way. – Basile Starynkevitch Jan 12 '18 at 18:07
  • Why "The jobs inside the inner shell won't be logged"? – Tim Jan 12 '18 at 18:08
  • Why would they be logged? – Basile Starynkevitch Jan 12 '18 at 18:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.