I currently run an background process started by a deamon process. It has no terminal and works fine as it doesn't have any screen i/o. It is started via a shell script which I can change. The shell script inherit the daemon's environment, set up additional environment variables and finally starts the program via exec $PROG arg1 "arg 2" 1>&2.

For running this in "debug mode" screen i/o is necessary (curses mode).

What I've tried so far:

  • exec screen -dmS FIXME $PROG arg1 "arg 2" results in a not starting program with the error message "invalid file descriptor"
  • exec $PROG arg1 "arg 2" 1>/dev/pts/5 results in a starting program, all output can be seen on /dev/pts/5, of course input isn't possible
  • exec $PROG arg1 "arg 2" 1>/dev/pts/5 <namedpipe results in a starting program, all output can be seen on /dev/pts/5, takes input via echo stuff > namedpipe from another session but this cannot be used as all function keys needs to be usable.

The "obvious" solution I thought of (but got not working):

  • start a screen in another console screen -dmS "FIXME"
  • let the background process use this screen session via exec screen -S "FIXME" -X stuff "$PROG arg1 \"arg 2\" " (newline is needed, it emulates pressing the Enter key)
  • attach to the screen via screen -r "FIXME" (reattaching works)

Problem here: This only sends the single command to the session, which doesn't work as the complete environment is missing (starting with the current directory, going on with all environment vars). [Edit: posted a possible solution hack as answer (the original question is still unanswered)]

Question: Is it possible to start the background process via screen utility? (Best option would be if the new screen session is started from the background process [problem here: this process has no console at all] and to simply reattach from another window.

If this isn't possible: Are there any other workarounds?


Doesn't answer the original question but likely works in most cases:

  • store everything from the environment that looks important to a temporary file
  • send the following commands to screen: change to directory, source the temporary file, remove the temporary file, start the program


   rm some_env.$$
   for e in $(env | grep "PATH\|WHATEVERISIMPORTANT")
      echo "$e" >> some_env.$$
   exec screen -S "FIXME" -X stuff "cls
cd $(pwd)
. some_env.$$
rm . some_env.$$
$PROG arg1 \"arg 2\"
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.