Pages

Tuesday, March 18, 2008

Controlling Jobs in Linux

% Stop and restart a Job
If you find your Linux machine is slow due to lots of daemons running on it and want some process to get more CPU time to finish up fast. here we go to controlling jobs.
leo@gnu:~$ kill -s STOP 5846 ###5846 is PID of the running process
leo@gnu:~$ ps x | grep daemon_wallpapoz
5846 ? Tl 0:14 python /usr/bin/daemon_wallpapoz
leo@gnu:~$ kill -s CONT 5846
leo@gnu:~$ ps x | grep wall
5846 ? Sl 0:14 python /usr/bin/daemon_wallpapoz

% Starting a Job in the Background
Attaching an ampersand to the end of a command will cause that command to run in the background.
For example:
leo@gnu# xcalc &
This command causes the xcalculator to run, also it frees up the bash prompt so you can perform other tasks.
You can also use this method when starting X-Windows
leo@gnu# startx &
This will start X-Windows, but it will also free up that console that was used to start X-Windows.

% Stopping (Pausing) a Job
Press CTRL+z to stop a job.

% Listing Jobs
You may list jobs and their status by running the "jobs" command.
[leo@gnu]# jobs
[1]+ Stopped less /etc/lilo.conf
[leo@gnu]#

% Resuming a Stopped Job [%1]
You may resume a stopped job by typing %jobnumber as follows:
[leo@gnu]# %1
An alternate method :
[leo@gnu]# fg %1

% Placing a Job in the Background [%1 &]
You may place a stopped job in the background by typing %jobnumber & as follows:
[leo@gnu]# %1 &
An alternate method :
[root@server /root]# bg %1

% Killing a stopped Job [kill %1]
You may kill a stopped job by typing kill %jobnumber as follows:
[leo@gnu]# kill %1

% The nohup Utility [nohup cmd &]
The nohup utility will run as a process that is detached from your console. If you close your console, the nohup process will keep running in the background.
[leo@gnu]# nohup scan_ip.sh &

% Capturing Output [script]
The "script" command will put you into a new shell and it will log all the output for you into the file called "typescript". When you are done collecting data, you may type "exit" to get out of this script shell.

No comments: