Linux Job Management Notes: Difference between revisions

From ITCwiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 40: Line 40:


To exit top type q and you are back to the command line.
To exit top type q and you are back to the command line.
The kill command is misleading in that it is not guaranteed to stop a process, but it does send a signal to the running process.  The operating system by default supplies each process with signal handlers to deal with incoming signal differently. To send the kill signal you need at least one parameter, and the process identification number from the ps command list.
The most common handlers are:
 9 the operating system simply kills the process,
 15 the SIGTERM signal you must clearly specify -15 or TERM to terminate
 1 to hang up also called SIGHUP OR HUP this signal gives the process time to perform a clean shutdown
''Example'': at the command line type kill –signal handler# PID# from ps command list
Remember that root users can kill any process, but standard users can only kill the processes they have permission to kill.

Revision as of 04:08, 14 July 2011

Job management and control: & condition, CTRL-Z, jobs, fg, bg

The user login shell is the first program that runs when you log into the workstation. The formal definition for this program is a command language interpreter that executes commands; also referred to as an interface between the user and the system. Bash (Bourne Again Shell) is a command line-only interface where programs also referred to as jobs are lunched and controlled, when a job starts it takes control of the terminal, when the job is finished, control is given back to bash, and a command line is redisplayed for the user. You can see a list of jobs that bash is tracking; along with their status, by using the jobs command.

Example: At the command line type jobs press Enter, the following information is displayed [Job number] Status of program, (running or stopped) Program name & after program name if used.

You can start a job using the ampersand & this states a condition that the job give up control of the terminal to bash, and give the user a command line while the job continues to run in the background.

Example: At the command line type program name & press Enter, the job continues to run in the background and you receive a command line and can continue working.

If a job is already running and has control of the terminal you can press CTRL+Z in the terminal window, the job will stop, give control back to bash, and you will receive a command line. When you bring a job that was running in the background to the foreground using the fg command you give control of the terminal back to that job. To bring a job to the foreground use this command:

Example: at the command line type fg job number from the jobs list

You can send a running job to the background using the bg command as follows:

Example: at the command line type bg job number from the ps jobs list.

To start a job stopped in the background bring it back to the foreground using fg, then if you want, you can send it back to the background using bg it will continue running in the background.

Processes: ps, top, kill signal

The ps command stands for process status it list all the processes in a system, if they are running, stopped, or in a zombie state. The most common parameter is ps auxww

Example: at the command line type ps auxww press Enter

It you want to look at the processes that are running on your system line by line you can use | less like this. Example: at the command line type ps auxww | less you can then use the down arrow to scroll line by line.

The top command shows what is running on your system in real time it refreshes every two to three seconds. Top is an interactive program with a command line within the program that can be used to prioritize or kill processes. To start the top program use the following command.

Example: at the command line type top press Enter

Top is a CPU hog if several people are using the program. To prevent other users from running this program you can change the permissions so only root users are allowed access.

Example: at the command line type chmod 0700 `which top`

To exit top type q and you are back to the command line.

The kill command is misleading in that it is not guaranteed to stop a process, but it does send a signal to the running process. The operating system by default supplies each process with signal handlers to deal with incoming signal differently. To send the kill signal you need at least one parameter, and the process identification number from the ps command list.

The most common handlers are:

 9 the operating system simply kills the process,

 15 the SIGTERM signal you must clearly specify -15 or TERM to terminate

 1 to hang up also called SIGHUP OR HUP this signal gives the process time to perform a clean shutdown

Example: at the command line type kill –signal handler# PID# from ps command list

Remember that root users can kill any process, but standard users can only kill the processes they have permission to kill.