By default you get notified about terminated jobs when you hit enter ,Try set -b to get notified immediately.
if no job id is mentioned bg and fg consider the most recent job
fg %3
command and it would have the same result. we can disable and enable shell job control feature withset +m and set -m
commands.
huponexit
option is set! shopt huponexit
to see if this is true.huponexit
is false, which is the default on at least some linuxes these days, then backgrounded jobs will not be killed on normal logout!huponexit
is true, then we can use nohup
or disown
to dissociate the process from the shell so it does not get killed when you exit. Or, run things with screen
.shopt -s huponexit
and shopt -u huponexit
in order to set and unset it.Nohup
stands for no hangup, and that means even if the parent shell is diconnected the job just will continue, The output of the nohup command will write in nohup.out the file if any redirecting filename is not mentioned in nohup command.Please notice that we can not usefg
,bg
commands on that particular job anymore.
We useually use nohup with output redirectionnohup bash script.sh > myresult.txt 2>&1
screen -s Session_Name
to start a named session.now lets run a command inside screen:Inorder to create a new screen inside the current screen (nested screen) use just press Ctrl-a +c
We usually usescreen -dr <Screen-ID>
command.This means detach the specified screen first and then reattach it.
If we use thejobs
command with the-l
option, it will also show process ID.
ps
will print four columns of information for minimum two processes running in the current shell, the shell itself, and the processes that run in the shell when the command was invoked.Note – Sometimes when we execute ps command, it shows TIME as 00:00:00. It is nothing but the total accumulated CPU utilization time for any process and 00:00:00 indicates no CPU time has been given by the kernel till now. In above example we found that, for bash no CPU time has been given. This is because bash is just a parent process for different processes which needs bash for their execution and bash itself is not utilizing any CPU time till now.
-a
, -u
and -x
. While a
= show processes for all usersu
= display the process’s user/ownerx
= also show processes not attached to a terminalWe can also use ps -ef instead of ps aux . There are no differences in the output because the meanings are the same. The difference between ps -ef and ps aux is due to historical divergences between POSIX and BSD systems. At the beginning, POSIX accepted the -ef while the BSD accepted only the aux form. Both list all processes of all users. In that aspect-e
andax
are completely equivalent.
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head -10
. With-o
or –format
options, ps allows us to build user-defined output formats.pgrep
command searches for processes currently running on the system, based on a complete or partial process name, or other specified attributes.Always use ps -ef command to make sure about process_name. There is different between process_name and the running program(like bash). compare pgrep -a and pgrep -af.
Real Time process monitoring ?Be creative and use combination of other commands like 'watch'. We can use 'watch' in conjunction with ps command to perform Real-time Process Monitoring :watch -n 1 'ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head'
man 7 signal
)kill
command in Linux (located in /bin/kill), is a built-in command which is used to terminate processes manually . kill command sends a signal to a process which terminates the process.kill -l
to see all signals you can send using kill.killall
is a tool for terminating running processes on your system based on name. In contrast, kill
terminates processes based on Process ID number (PID). Like kill
, killall
can also send specific system signals to processes.killall
to wait until the process terminates before exiting.free
command displays the total amount of free space available along with the amount of memory used and swap memory in the system, and also the buffers used by the kernel.-b
for bytes, -k
for kilobytes, -m
for megabytes, or -g
for gigabytes.-t
displays an additional line containing the total of the total, used and free columns:uptime
command shows you a one-line display that includes the current time, how long the system has been running, how many users are currently logged on, and the system load averages for the past 1, 5, and 15 minutes. uptime -h
to see all of uptime
availbale options:R
running or runnable (on run queue)D
uninterruptible sleep (usually IO)S
interruptible sleep (waiting for an event to complete)Z
defunct/zombie, terminated but not reaped by its parentT
stopped, either by a job control signal or because it is being traced<
high-priority (not nice to other users)N
low-priority (nice to other users)L
has pages locked into memory (for real-time and custom IO)s
is a session leaderl
is multi-threaded (using CLONE_THREAD, like NPTL pthreads do)+
is in the foreground process group