To launch a process into the background, you can simply add a space and an ampersand after your command.
$ top & [1] 26452
This forces your program to run in the background. The shell will tell you that one process has started and show its process identification (PID) number.
You can use the shell to check on the process.
$ ps aux | grep 26452 user 26452 0.0 0.0 2072 660 pts/2 T 09:06 0:00 top
Also, you can bring a background process to the foreground.
$ fg 26452
If you no longer wish to leave the process running, you can also kill the process while it is in the background.
$ kill -9 26452
Or, you can force it to restart.
$ kill -HUP 26452
Here is a list of the available signals, from wiki http://en.wikipedia....%28computing%29
Quote
SIGABRT - process aborted
SIGALRM - signal raised by alarm
SIGBUS - bus error: "access to undefined portion of memory object"
SIGCHLD - child process terminated, stopped (*or continued)
SIGCONT - continue if stopped
SIGFPE - floating point exception: "erroneous arithmetic operation"
SIGHUP - hangup
SIGILL - illegal instruction
SIGINT - interrupt
SIGKILL - kill
SIGPIPE - write to pipe with no one reading
SIGQUIT - quit
SIGSEGV - segmentation violation
SIGSTOP - stop executing temporarily
SIGTERM - termination
SIGTSTP - terminal stop signal
SIGTTIN - background process attempting to read ("in")
SIGTTOU - background process attempting to write ("out")
SIGUSR1 - user defined 1
SIGUSR2 - user defined 2
*SIGPOLL - pollable event
*SIGPROF - profiling timer expired
*SIGSYS - bad syscall
*SIGTRAP - trace/breakpoint trap
SIGURG - urgent data available on socket
*SIGVTALRM - signal raised by timer counting virtual time: "virtual timer expired"
*SIGXCPU - CPU time limit exceeded
*SIGXFSZ - file size limit exceeded
SIGALRM - signal raised by alarm
SIGBUS - bus error: "access to undefined portion of memory object"
SIGCHLD - child process terminated, stopped (*or continued)
SIGCONT - continue if stopped
SIGFPE - floating point exception: "erroneous arithmetic operation"
SIGHUP - hangup
SIGILL - illegal instruction
SIGINT - interrupt
SIGKILL - kill
SIGPIPE - write to pipe with no one reading
SIGQUIT - quit
SIGSEGV - segmentation violation
SIGSTOP - stop executing temporarily
SIGTERM - termination
SIGTSTP - terminal stop signal
SIGTTIN - background process attempting to read ("in")
SIGTTOU - background process attempting to write ("out")
SIGUSR1 - user defined 1
SIGUSR2 - user defined 2
*SIGPOLL - pollable event
*SIGPROF - profiling timer expired
*SIGSYS - bad syscall
*SIGTRAP - trace/breakpoint trap
SIGURG - urgent data available on socket
*SIGVTALRM - signal raised by timer counting virtual time: "virtual timer expired"
*SIGXCPU - CPU time limit exceeded
*SIGXFSZ - file size limit exceeded
Lastly, if you do not wish for your process to send error messages to the terminal, you can launch them into the background, & redirect error messages to /dev/null.
$ top 2> /dev/null &
In this situation, the 2 represents Standard Error File Descriptor. You have the following 3 File Descriptiors available.
Quote
0 : Standard Input (Generally the Keyboard)
1 : Standard Output (Generally the Monitor)
2 : Standard Error
1 : Standard Output (Generally the Monitor)
2 : Standard Error
It is important to remember, that just because you are running a process in the background does not make it a daemon process! A background process is one which depends on terminal. Once the terminal is closed, the background process will die. However,if it is daemon process, it executed by init, so it will continue until the operating system is shutdown.
For more information, see the Unix/Linux man pages on fg and bg.




MultiQuote





|