How to open process again in linux terminal?
As noted, best practice is to use screen or tmux (before starting the program, so you do not need to ask this question).
But you can also attach to a running process with a debugger such as gdb (alluded to here as ddd
, a wrapper for gdb), as well as with strace (see this question). That's better than nothing - but gdb and strace would not give you the program's command-line again (though this question suggests a way). At least strace could give you some clues of what the program was attempting to print.
Change back into a running process on Linux after you put it into the background
If it's started from current shell, use standard job-control e.g.
$ jobs
$ gedit &
[1] 3341
$ jobs
[1]+ Running gedit &
$ fg %1
gedit
How do I run two ongoing processes at once in linux/bash?
When you say priority, you probably mean the nice-level of the process. To quote Wikipedia:
nice is a program found on Unix and Unix-like operating systems such
as Linux. It directly maps to a kernel call of the same name. nice is
used to invoke a utility or shell script with a particular priority,
thus giving the process more or less CPU time than other processes. A
niceness of −20 is the highest priority and 19 or 20 is the lowest
priority. The default niceness for processes is inherited from its
parent process, usually 0.
Running a process in the background does not inflict on it's nice-level. It's entirely the same as when you're running it in the foreground.
So you can easily run your application/process in the background by invoking it with a trailing '&'-sign:
my-server &
You can also send a foreground-process to the background, by pressing ctrl+z (pauses the execution) followed by bg+enter.
You can list running background-tasks with the command jobs.
To get it back to the foreground you must find out its job-ID with the jobs-command, and run fg [job-ID] (for example: fg 1)
Background tasks will send all their output to your shell. If you don't want to see their output, you'll need to redirect it to /dev/null:
my-server 1>/dev/null &
...which will redirect normal output into the void. Errors will still be visible.
How can I put the current running linux process in background?
Suspend the process with CTRL+Z then use the command bg
to resume it in background. For example:
sleep 60
^Z #Suspend character shown after hitting CTRL+Z
[1]+ Stopped sleep 60 #Message showing stopped process info
bg #Resume current job (last job stopped)
More about job control and bg
usage in bash
manual page:
JOB CONTROL
Typing the suspend character (typically ^Z, Control-Z) while a process is running causes that process to be stopped and returns control to bash. [...] The user may then manipulate the state of this job, using the bg command to continue it in the background, [...]. A ^Z takes effect immediately, and has the additional side effect of causing pending output and typeahead to be discarded.bg [jobspec ...]
Resume each suspended job jobspec in the background, as if it had been started with &. If jobspec is not present, the shell's notion of the current job is used.
EDIT
To start a process where you can even kill the terminal and it still carries on running
nohup [command] [-args] > [filename] 2>&1 &
e.g.
nohup /home/edheal/myprog -arg1 -arg2 > /home/edheal/output.txt 2>&1 &
To just ignore the output (not very wise) change the filename to /dev/null
To get the error message set to a different file change the &1
to a filename.
In addition: You can use the jobs
command to see an indexed list of those backgrounded processes. And you can kill a backgrounded process by running kill %1
or kill %2
with the number being the index of the process.
Related Topics
Use Df Command to Show Only the %Used
No Such File or Directory "Limits.H" When Installing Pillow on Alpine Linux
What Is the Reason for Performing a Double Fork When Creating a Daemon
How to Execute a Program from Python? Os.System Fails Due to Spaces in Path
How to One Hot Encode in Python
What Is the Correct Way to Include Localisation in Python Packages
Serving a Request from Gunicorn
Passing Extra Arguments Through Connect
I Can't Install Pyaudio on Windows? How to Solve "Error: Microsoft Visual C++ 14.0 Is Required."
Why Does This Code for Initializing a List of Lists Apparently Link the Lists Together