command execution with nohup in background
The &
at the end indicates that the command should be running in the background. That means, you can continue to enter commands into the shell.
For your particular question, it does not make any difference as it seems you want to close the terminal window right afterwards anyway.
what is the time about nohup command execute in shell?
It's because you put the nohup
command in the background with &
.
There is no output immediately from the command when you put it in the background as it is running in a separate shell, and your current shell immediately goes to the sleep
command. By the time you return from sleep, the nohup
background process has returned and outputs the value.
If you remove the &
(and thus run the commands in the same shell) you will see the order changes.
How to get execution time of a specific script that is running, but in the background?
You can add execution time nohup
log by execution the command on this way:
nohup /usr/bin/time php script...
Having to hit enter with nohup command in bash
It looks like you have shell debug tracing (set -x
mode) turned on, meaning bash will print each command before executing it (but after expanding variables etc). Since the nohup java ...
command is backgrounded, this happens asynchronously, and happens to get printed after the shell has printed its prompt, so you get "$
" (your shell prompt) followed by "+ nohup java ...
(the debug trace).
(Note: you have errors & output from the command redirected to nohup.out, but since the trace is printed by the shell, not the command itself, the redirect doesn't apply.)
You don't actually need to press return at this point; the only thing pressing return does is get you a new, clean (not mixed with debug tracing) prompt. You could just enter another command as normal. However, since the shell is confused about where on the line you are, features like command editing and history recall may not work properly.
If you want to avoid this, I think your main options are to either turn off debug tracing (set +x
) before running the command, or add a delay before the shell prints its next prompt:
nohup java -jar webservices-0.0.1-SNAPSHOT.jar > nohup.out 2>&1 & sleep 1
Here, the nohup java ...
command runs in the background as usual, but the sleep 1
command runs in the foreground and so the shell won't print its next prompt for a second (which should be enough time for the background process to print its debug trace).
How to execute linux command in background?
nohup sleep 10 2>/dev/null &
The nohup
command prints a message to stderr, and 2>/dev/null
sends stderr to /dev/null
.
Related Topics
Bash Script for Executing Commands on Multiple Server
Find String Inside PDF with Shell
Linux Allocates Memory at Specific Physical Address
Perl and Bash Variable Substitution, with Hexadecimal Characters and Repeat Count
Compare Two Files of Different Columns and Print Different Columns
Required Alignment of .Text Versus .Data
How to Clone a Git Repository Which Is Present on a Remote Linux Server into Windows
Bash Command to Search for Any Occurrence of Phrase and Return List of Files and Paths
Make Uses "Cc" Instead of "Arm-None-Eabi-As"
Having an Issue Passing Variables to Subshell
How to Do an Initial Setup of Slapd Olc with Ldapmodify
How to Strip Down My Yocto Linux
Brother Ql-720Nw Specifying Media Size Seems Ignored
Arduino Upload Error "Stk500_Recv(): Programmer Is Not Responding" in Fedora
Shell Must Parse Ls -Al Output and Get Last Field (File or Directory Name) Any Solution
Adding Stackless Threading to Bsd Kernel
How to Use Multiple Threads for Zlib Compression (Same Input Source)