Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to run a program in a chroot while still having access to stdin/stdout?

My first attempt was a shell script:


chroot /var/lib/app-root /usr/bin/app $*

Then symlinked it where things expect to see it:

ln -s /usr/local/bin/real-app /usr/local/bin/app

But two issues here. First, the program requires root to run. I can deal with that. But second, there no longer seems to be a connection to STDIN/STDOUT which is how the parent process expects to control this application.

Is there a way to make this work? Do I need to have the app modified so it performs the chroot syscall itself?

share|improve this question
There may be some other problem actually, because, come to think of it "chroot /var/lib/chroot /bin/bash" does exactly this, right? Interactive shell started by the caller with stdin/stdout.... hmm. – Mark Renouf Oct 20 '09 at 14:30

chroot should not affect stdin, stdout or any other file descriptors which are open at exec time. I don't know what your shell chroot command does, but provided it doesn't close them, then it should all work fine.

That is, provided the program doesn't do something really silly like rely on opening /dev/stdout or anything.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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