nohup ⌃Z vs ⌃C

nohup (script call / run) &

If it’s running longer than expected or still occasionally suspends, here are a couple of troubleshooting tips:

  1. Process Time: Some checks can be lengthy depending on directory size or network conditions (e.g., broken link check if URLs are slow to respond). You might consider running each script individually to identify any particularly slow sections.

  2. Monitoring Output: You can add set -x at the beginning of the script to enable verbose debugging, which will show each command as it’s executed. This might help pinpoint any spots where it hangs.

  3. Running in Background: If running directly in a terminal, consider adding nohup to run it in the background without terminal suspension:

    nohup ~/scripts/run_all_checks_exclude_build.sh /path/to/project test1 &
    

    This will create an output file (nohup.out) for any stdout/stderr, while your results should still save to the specified results file.

 

[3]  + 70538 suspended  ~/scripts/run_all_checks_exclude_build.sh  check1 ❯ nohup ~/scripts/run_all_checks_exclude_build.sh /Users/spiffy/Documents/nsgandolf/_stage/stage-smp checker1 & [4] 70680 appending output to nohup.out 

Running the script with nohup in the background will prevent it from being suspended if you close your terminal session or if there’s any interruption in the foreground process.

Here's a quick breakdown of what’s happening:

  • nohup: Keeps the script running even if the terminal is closed or disconnected.
  • &: Runs the script in the background.
  • appending output to nohup.out: By default, any output (stdout or stderr) from the script will go to nohup.out in the current directory.

If the script generates output to the specified results file (e.g., results_exclude_build_checker1_<timestamp>.txt), you can also monitor nohup.out separately to check for any real-time errors or status updates. You can view nohup.out at any time by using:

tail -f nohup.out

 

If you'd like the script to print directly to the terminal, you don’t need to use nohup. Running the script as you did originally without nohup and without & at the end will display output in the terminal and allow you to monitor progress or stop it quickly if needed. Here’s the command:

~/scripts/run_all_checks_exclude_build.sh /Users/spiffy/Documents/nsgandolf/_stage/stage-smp checker1

This approach will:

  • Print all output directly to the terminal.
  • Allow you to press Ctrl + C at any time to stop the script immediately if it’s not working as expected.

Only use nohup and & when you want the script to run in the background without real-time monitoring.

 

The difference between Ctrl + Z and Ctrl + C lies in how they interact with processes in the terminal:

  • Ctrl + C (SIGINT): This sends an "interrupt" signal to the process, telling it to terminate immediately. This is commonly used to stop scripts, commands, or programs that are actively running. It’s a direct way to stop a process.

  • Ctrl + Z (SIGTSTP): This sends a "stop" signal, which suspends the process and sends it to the background, effectively pausing it. The process is still in memory and can be resumed later. After using Ctrl + Z, you can resume the process by using:

    • fg to bring it back to the foreground.
    • bg to let it continue running in the background.

When to Use Each:

  • Ctrl + C is typically used to stop commands that don't need to continue or that you want to halt completely.
  • Ctrl + Z is helpful if you want to pause a command temporarily, perhaps to run something else, and then return to it without terminating.

In summary:

  • Use Ctrl + C to completely stop something.
  • Use Ctrl + Z to pause it for later resumption.

 

When you press Ctrl + Z, the process is paused (suspended) but remains in memory. Here’s what happens to a Ctrl + Z process under different scenarios:

  1. When You Close the Terminal:

    • If the terminal closes, suspended processes are typically terminated. The operating system sends a signal (SIGHUP) to any remaining processes tied to that terminal session, which usually causes them to exit.
  2. When You Log Out or Restart the System:

    • Upon logging out, all terminal processes associated with the session will be terminated.
    • A system restart stops all processes, including any that were suspended.
  3. If You Leave the Terminal Open:

    • The suspended process stays paused indefinitely in the background until you bring it back to the foreground with fg or continue running it in the background with bg.

Keeping Suspended Processes Active

If you need the process to keep running even after closing the terminal, you can:

  • Use nohup before the command to prevent the process from receiving the SIGHUP signal when the terminal closes.
  • Start it with screen or tmux, which create a persistent session you can detach from and reattach to later.

Checking Suspended Processes

To see any suspended jobs in a session, type jobs in the terminal, which will list them and show their status.

 

 

 ❯ jobs [1]    suspended  ~/scripts/run_all_checks_exclude_build.sh  check1 [2]  - suspended  ~/scripts/run_all_checks_exclude_build.sh  check1 [3]  + suspended  ~/scripts/run_all_checks_exclude_build.sh  check1 [4]    running    nohup ~/scripts/run_all_checks_exclude_build.sh  checker1

 

 

To kill the suspended and background processes, you can use the following commands:

  1. List the jobs with their job numbers (you've already done this with jobs):

    jobs
    

    This shows you the list of jobs with their numbers, like [1], [2], [3], etc.

  2. Kill each suspended job using its job number by running:

    kill %1
    kill %2
    kill %3
    

    This sends a termination signal to each job, ending it. The % symbol is used to reference job numbers in the shell.

  3. Confirm they're terminated by running jobs again. You should no longer see the killed jobs listed.

  4. To kill the background nohup process (e.g., [4] in your list):

    • If you want to terminate it, use:

      kill %4
      
    • Alternatively, if you know the process ID (PID), you can kill it with:

      kill <PID>
      

After this, your terminal should be clear of the unwanted suspended and background processes.

Scroll to Top