1

I have a script.sh which I start in Xvfb new session this way:

Xvfb :10 -screen 0 1000x200x24 & export DISPLAY=":10" && script.sh

In script.sh I run one c++ program and one java program. However, I sometimes got errors in one or two of them: in c++ program I got Segmentation fault and java program I got exception something like awt can't get display:10. The errors disappeared when I added in the beginning of script.sh the line

sleep 2;

After that I didn't get any errors. How to explain it?

Pavel_K
  • 329
  • 1
  • 5
  • 18

1 Answers1

2

This question is similar to How to launch Xephyr without sleep-ing. Your applications try to access Xvfb before it is ready. The cleanest way to solve this is to use xinit. Run Xvfb with

xinit script.sh -- /usr/bin/Xvfb :10

(include export DISPLAY=:10 into script.sh)

mviereck
  • 2,377
  • 1
  • 18
  • 18
  • Thank you very much for your answer. I will try. Can you say - if I follow your solution, can other programs (which are not in script.sh) be later started in this session? – Pavel_K Feb 14 '17 at 17:15
  • @Pavel yes, you can run other applications with `DISPLAY=:10 otherapp` – mviereck Feb 14 '17 at 17:22
  • Do you mean I can run other applications from outside that session? For examplie if in script.sh only one program - gedit. How I inside that session somehow run another program? I mean there is no terminal etc. – Pavel_K Feb 14 '17 at 17:26
  • You can run any program from anywhere in this Xvfb session.It just needs DISPLAY to be set. – mviereck Feb 14 '17 at 17:28
  • Thank you very much. But could you explain how can I from Xvfb session start another application in that XVfb session if there is only one application - gedit (text editor)? I need to know it for security reasons. – Pavel_K Feb 14 '17 at 17:32
  • This seems to be not related to your origin question, you should create a new one. I'm not sure what you are pointing to. gedit in Xvfb is useless, as it does not provide a keyboard or monitor to interact. If security is a concern, you may use cookie authentication. – mviereck Feb 14 '17 at 17:45
  • If your target is to isolate an application from your system, you can use docker. If it needs an X display, you can use [x11docker on github](https://github.com/mviereck/x11docker) to run GUI applications in docker. – mviereck Feb 15 '17 at 00:10