Linux csh script going to Suspended (tty output) when running with & (bg)

i have strange behavior i have csh file that run java process something like this :

run_server.csh

    #!/usr/bin/tcsh
    
    java -Dtest=testparam -cp ${TEST}/lib/device.jar:${TEST}/conf:${TEST}/lib/commons-logging-1.1.1.jar  com.device.server

when i run it like this :

run_server.csh&

in the putty shell in linux
im getting this massage :

    [2]  + Suspended (tty output)        run_server.csh

Although when i run it without the ampersand the server is running and outputting its log massages into the stdout but the problem is when i press ctr+c the process is killed

another strange thing is if i write wrapper script to run_server.csh
that looked like this run_server_wrapper.csh:

    #!/usr/bin/tcsh 
    run_server.csh &
    sleep 5

it does run the server as bg process and the run_server_wrapper.csh it self
getting the massage :

    [2]  + Suspended (tty output)        run_server_wrapper.csh

what is the problem here ?

If a background process tries to read from the terminal, it will be stopped. This is normal terminal and shell behavior. Only foreground processes are allowed to control the terminal like that.

To prevent it from reading from the terminal, run it with nohup to prevent it from accessing the terminal. This will redirect stdin/stdout/stderr automatically. stdin will connect to /dev/null, while stdout and stderr will be saved to a file in the current directory.

nohup run_server.csh

As Corona688 said, you better use nohup , but I think he missed the & at the end.

nohup run_server.csh &

Thanks for the replays even if i added the nohup and the "&" at the end i still have the same problem

Then your java program must be opening /dev/tty directly, that would also freeze it.

Are you on Linux? You could do

setsid nohup ...

to put it in a new session group, independent of the current terminal.

ok asked the developers to remove all prints to stdout
Thanks!

No, don't do that!

Reading from the controlling terminal gets it frozen. Writing is usually okay.

1 Like

I came across a very similar issue trying to run a minecraft server on linux a few years back.

This is also a java program that needs terminal I/O. I got around the issue using gnu screen.

This is quite nice as you can give each screen a unique name and then later use "-X stuff" to jam keyboard input to the backgroup process like this:

screen -p 0 -S minecraft -X stuff "$(printf "%s\r" "say SERVER BACKUP STARTING...")"
1 Like