0

I have a bash script that needs to be executed with nohup due to its long execution time. How can I verify if the script is currently running with nohup, or if there are alternative methods to ensure this?

I am considering automatically restarting the script with nohup, but I'm concerned if this could cause any issues, especially if it was initially launched with nohup.

I've tried to identify the process using the PID with the commands "ls -l /proc/[PID]/fd" and "ps aux". Unfortunately, these commands do not clearly show whether nohup was used. They merely indicate that the output is being redirected from the terminal to a different location. In addition, while the 'jobs -l' command shows that the script is running with nohup from the terminal, I'm unable to verify this within the script itself because the script runs in its own shell so lacks the necessary access to the jobs of the parent shell

3
  • 2
    I would suggest not. Whether you use nohup to run the script or run it in the background or whatever should be the responsibility of whomever or whatever launches the script, not of the script itself. Commented Jul 19, 2023 at 17:46
  • 1
    Write a log file in your script. Commented Jul 19, 2023 at 18:05
  • Maybe look at ppid and see if your parent is nohup. Commented Jul 19, 2023 at 18:10

1 Answer 1

1

If GNU screen is installed, you can use the screen command

screen -dmS myprogram script-you-want-to-run.sh

You can then resume by using

screen -r myprogram
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.