Asynchronous shell commands

后端 未结 5 1596
一向
一向 2020-12-04 08:48

I\'m trying to use a shell script to start a command. I don\'t care if/when/how/why it finishes. I want the process to start and run, but I want to be able to get back to my

5条回答
  •  旧巷少年郎
    2020-12-04 09:38

    Everyone just forgot disown. So here is a summary:

    • & puts the job in the background.

      • Makes it block on attempting to read input, and
      • Makes the shell not wait for its completion.
    • disown removes the process from the shell's job control, but it still leaves it connected to the terminal.

      • One of the results is that the shell won't send it a SIGHUP(If the shell receives a SIGHUP, it also sends a SIGHUP to the process, which normally causes the process to terminate).
      • And obviously, it can only be applied to background jobs(because you cannot enter it when a foreground job is running).
    • nohup disconnects the process from the terminal, redirects its output to nohup.out and shields it from SIGHUP.

      • The process won't receive any sent SIGHUP.
      • Its completely independent from job control and could in principle be used also for foreground jobs(although that's not very useful).
      • Usually used with &(as a background job).

提交回复
热议问题