help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] running in background, sleep and back to normal prompt


From: Bob Proulx
Subject: Re: [Help-bash] running in background, sleep and back to normal prompt
Date: Sat, 16 Feb 2013 11:26:43 -0700
User-agent: Mutt/1.5.21 (2010-09-15)

adrelanos wrote:
> ./test &
> 
> Will result in.
> 
> /tmp/test $ ./test &
> [2] 32420
> /tmp/test $ ...
> _

Yes.  The script was launched in the background.  Bash notified you of
the job control number assigned to it and the process id.  The job
control number may be used in bash with the above would be %2.  You
could 'fg %2' or 'kill %2' and so forth.

> After pressing <enter>.
> 
> [2]+  Done                    ./test
> /tmp/test $

Yes.  At that time the script had exited.  Bash is notifying you that
the process being monitored with job control has exited.  This means
that use of %2 for job control is no longer attached to that process.

> Questions:
> 
> How can I get ride of the "[2] 32420"?

Do not put the task in the background.  This is a notification for
background jobs.  If you don't put the task in the background then
there won't be a notification of this message.

If you still want something in the background then you can have the
script put itself in the background or have it put the subsequent task
in the background.

> How can I get ride of the "[2]+  Done                    ./test"?

Turn off job control monitoring.

Either:
  set +m
Or:
  set +o monitor

With job control monitoring off bash won't monitor the status of
background processes.

> How can I get back to the normal prompt, for example "/tmp/test $" with
> requiring to press enter?

There is some misunderstanding here.  A normal prompt is always
printed.  There is no need to press enter to get a normal prompt.

I think you are being confused by the nature of asynchronous
background tasks.  The 'test' script is connected to stdout and
stderr.  The test script is sleeping for a bit.  After it sleeps it
is printing output which is followed by a newline.  This output is not
monitored by the shell.  It came after the prompt was printed.  The
output is on the terminal.  The newline leaves the cursor on a blank
line.  The shell does not know anything about this.

I think you are asking for the shell to track the output of the
background task and to *add an additional* prompt after the background
program has printed a newline.  Of course that isn't possible nor
desirable.

If output from background processes being merged in with foreground
process output is not what you want then redirect the output of the
background process to a file.

  $ ./test >test.out &

That isn't what you asked but that should do what you want.  Give it a
try and let us know.

BTW 'test' is a terrible name because it can be confused with the
'test' builtin.  Using 'trial' or 'mytest' some such is better.

Bob



reply via email to

[Prev in Thread] Current Thread [Next in Thread]