Korn Shell script in stopped state while running in background

Hi,

I want to run a shell script in background .
but its going to stopped state

$ ksh cat_Duplicate_Records_Removal.ksh &
[2]     8975
$
[2] + Stopped (tty output)     ksh cat_Duplicate_Records_Removal.ksh &

why is this happening?

Also could anyone please tell me what is a stopped state and what is the use of it?

It seems ksh doesn't ignore SIGTTOU, which is sent when a background process tries to write to a terminal. This question was just asked by alexcol http://www.unix.com/unix-for-dummies-questions-and-answers/257477-nohup-command-gets-status-stopped.html

Try redirecting to files ksh >stdout.log 2>stderr.log & or /dev/null
Also consider using nohup

1 Like

Thank You..
but my script is not writing anything to the terminal(I have redirected all output to logfile).
I ran the script in foreground and it completed successfully without sending any output/error to the screen

$ ksh cat_Duplicate_Records_Removal.ksh
$

Is there any other reason why my script is stopped?

Maybe nothing visible was sent to the stdout (usually the screen) but we can see inside to know for sure. Perhaps something prepares to write even though there is no actual output.

Can you share your code?

Robin

maybe you can trap SIGTTOU and ignore it in your script...
maybe you can coerce the terminal not to send it: stty -tostop

ok i ran the script in background

$ nohup ksh cat_Duplicate_Records_Removal.ksh >/dev/null 2>&1 &
[1]     6679
$ exit
You have running jobs
[1] + Stopped (tty output)     nohup ksh cat_Duplicate_Records_Removal.ksh >/dev/null 2>&1 &
$

now the problem is when i type exit, the job is getting stopped.
why is that?

Thank you

It seems it's still suffering from the original problem. I wonder if redirecting stdin would help </dev/null .

disowning the process should allow you to exit cleanly. nohup ksh ... & disown

That may let you exit cleanly, but how will the process ever end from this stopped state?

Ok..i have rewritten the command as follows

nohup ksh cat_Duplicate_Records_Removal.ksh </dev/null >/dev/null 2>&1 &

earlier when i run the command in background and when enter(CR) is pressed the job got stopped . Now with the inclusion of </dev/null that problem is solved.:b::b:

when i type disown in HP-UX ksh ..I get the following

$ disown
ksh: disown:  not found

is there any alternative to disown?

Not that I'm aware of. I guess I should have started by asking your OS and $KSH_VERSION .

You should be able to exit by trying exit twice. But I've not dealt with such a system, at least not for a long time.

Nowadays I keep a terminal multiplexer (tmux or GNU screen) running that I can detach and reattach to. My current jobs stay running in virtual terminals which I can just switch to and view the output instead of putting them unattended in the background. Of course, this isn't the right solution for everything but it's worth investigating if you're able to install such software.

1 Like

I think the command 'at' can be also used to run scripts without getting stopped on logout.

at command

The command 'at' can be scheduled to run a script at a particular time or immediately

ksh93 supports the disown command. You must be using a really old version of ksh such as ksh88 or pdksh.

I think if you don't have disown, you don't need it either.