Find the answer to your Linux question:
Results 1 to 6 of 6
Hi! I have an application that runs in the console, writes some things to the standard output. When I try to run it in the background, something like this happens: ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jan 2007
    Posts
    27

    Question running command-line app in the background ==> stopped


    Hi!

    I have an application that runs in the console, writes some things to the standard output. When I try to run it in the background, something like this happens:

    > myapp >output.txt &
    [1]+ Stopped myapp >output.txt
    > fg
    <writing to output.txt...>
    > [CTRL+Z]
    [1]+ stopped myapp
    > bg
    [1]+ myapp >output.txt &

    [1]+ Stopped myapp >output.txt &

    ==> this is the problem here. It simply changes to the stop state immediately when it's "told" to run in the background.

    Is there any general reason for this or does that seem something application-specific?


    Thanks,
    Agoston

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,533
    If it is waiting for some stdin input, then it may well stop like this. What happens if you move it back to the foreground? Does it continue to run successfully? Is it a script or is it a binary executable?
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Jan 2007
    Posts
    27
    It's not waiting for user input because I can run it without any problems in the foreground without it asking for any.

    If I issue 'fg', thus putting it into the background, it runs on without any problem.

    It's actually a Java class that runs over the JVM. There are other Java classes in the project I'm working on that run fine in the background this way.

    So I'm really stuck.

  4. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,533
    At this point I need to see your code, or you need to run it in the debugger in order (as a background process) in order to see where it is stopping and possibly determine why.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  5. #5
    Just Joined!
    Join Date
    Jan 2007
    Posts
    27
    Well, I would say your reply pretty much answers my original question, i.e., whether this is something of a general problem with bash (or the way I'm using it at least) or I should rather look for the reason in the code.

    So thanks a lot for the answer, I suggest we not pursue this issue any further.


    Cheers,
    Agoston

  6. #6
    Just Joined!
    Join Date
    Jan 2007
    Posts
    27
    I've found the solution. Actually it had absolutely nothing to do with bash.

    The problem was that the Java class was run with ant, where fork="true" was specified. Now the ant documentation says:

    "If you run Ant as a background process (like ant &) and use the <java> task with spawn set to false and fork to true, you must provide explicit input to the forked process or Ant will be suspended because it tries to read from the standard input."

    This was exactly the case.

    So case solved.

    Cheers,
    Agoston

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •