Why Do I Get The Information of "Suspended (Tty Input)" When I Run My Script in The Background

why do I get Suspended (tty output) in one terminal but not in others?

This will fix it:

stty -tostop

From the man page:

tostop (-tostop)

Send (do not send) SIGTTOU for background output. This causes background jobs to stop if they attempt terminal output.

This tostop is normally the default setting, as it's usually undesirable to mix the output of multiple jobs. So most people just want the foreground job to be able to print to the terminal.

How to resume a suspended (tty input) process [unix/mac]?

To add to the Chaitanya Bapats answer,

you can use jobs command to list the suspended jobs. The output will be something like this if you have more than one suspended jobs.

[1]  - suspended  sleep 400
[2] + suspended sleep 300

You can bring the job to foreground by using fg. If you have more than one suspended jobs, then you can use fg %ID. ID is the value inside [] in the output of jobs command.

Also, if you want to resume the job without bringing it to the foreground, you can use kill -CONT command. Example usage:

kill -CONT JOBID

You can also use bg command to move job to background. bg will resume the last suspended job. Also, bg %ID will resume the job with [ID] in jobs command output

running ssh process in background gets paused

When a background process attempts to read from standard input, it is sent a signal which suspends it. This is so the user can bring the process to the foreground again and provide the necessary input.

If no input needs to be provided, you can redirect the standard input from /dev/null, either when calling test_remote or in cmd.



Related Topics



Leave a reply



Submit