Linux Job Management Notes: Difference between revisions

From ITCwiki
Jump to navigation Jump to search
No edit summary
 
(One intermediate revision by one other user not shown)
Line 162: Line 162:
CFDisk is a tool that is used to partition a hard disk it is a Linux partition editor, similar to fdisk, but with a different user interface.
CFDisk is a tool that is used to partition a hard disk it is a Linux partition editor, similar to fdisk, but with a different user interface.


The mkfs command makes a new file system on a specified device the mkfs command initializes the file system label and startup block.
The mkfs command makes a new file system on a specified device the command initializes the file system.


The mount command serves to attach the file system found on some device
The mount command serves to attach the file system found on some device.

Latest revision as of 19:43, 18 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 # 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 # 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 Enter 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 for quit 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.


Start up: Booting the system, GRUB, stage 1, stage 2,

The boot loader is the first software program that runs when the computer starts, it hands control of the computer over to the operating system. The boot loader is located in the MBR Master Boot Record of the disk. The most common boot loader is GRUB the Grand Unified Bootloader. The GRUB boot process take place in two necessary stages using special image files, each stage helps the next stage along.

Stage 1 The image file in this stage is called stage 1 it is used for booting up GRUB the boot loader. The image file can then either load stage 1.5 or load stage 2 directly.

Stage 2 This image can consist of two types of images, image 1 is an optional image that understands the semantics of one file system or the other, and has a name like file system name_stage1_5 this image serves as a bridge between stage 1 and stage 2. At this point, either directly form stage 1 or from image 1.5 stage 2 image is loaded it contains the code to load the kernel that boots the operating system, that displays boot menu and contains GRUB shell to enter commands.


Bootstrapping

After the GRUB is started the kernel is loaded in the first megabyte of RAM random access memory to accomplish this the kernel is compressed, the head of the file contains the code to bring the CPU into protected mode. In this stage the kernel executes its virtual memory subsystem, root files, device divers, mounts the root files, and starts a program called init. The init is the first non-kernel process to start and is always process ID number 1.


Runlevels /etc/inittab,

The init program reads its configuration file /etc/inittab, and determines what runlevel to boot in, and what rc scripts to run and stop at each runlevel. If the runlevel initdefault exists it is automatically selected, if not, you are asked for a runlevel value. Each runlevel between 0 and 6 has a special purpose.

 0 - System Halted

 1 - Single User Mode

 2 - multiuser Mode, but without networking file system NFS

 3 - Full multiuser mode normal

 4 - Not yet Defined

 5 - Same as runlevel 3, except using an X Windows login instead of a text based login

 6 - Shutdown & Reboot


Rc scripts, chkconfig

The rc scripts are used to manage services in the runlevel directories. The /etc/rc.d/rc directory is responsible for calling up the scripts in the right numerical order for each runlevel. Each runlevel has a subdirectory /etc/rc.d that follows the naming arrangement of /etc/rc1.d would be the subdirectory for runlevel 1. The runlevel directories have symbolic links to scripts in the /etc/rc.d/init.d that performs the process of starting and stopping services. If they are marked with an S the script is to start a service or K if the script is to kill (stop) the service the letters must be capitalized or the script will not recognize them. The order that the scripts are to run in is also important if script 2 depends on script 3 than script 3 must be run before script 2 can run. To look at the runlevel 3 directory

Example: at the command line type: ls –l /etc/rc.d/rc3.d/ press Enter

You can list and manage runlevels using the chkconfig utility from the command line to see a list for a certain program

Example: at the command line type chkconfig –list program name press Enter

to turn on or off a program at the command line

Example: type chkconfig –level # program name on/off


Booting and shutting down, fsck

The job of making sure the systems hard disk is in a reliable state is shared by the runlevel scripts and a file called /etc/fstab file. The fsck stands for file system check program is used to check and repair the file system it automatically runs during the boot process. If the system shuts down without any problems the autofsck file is deleted, and fsck will run without any problems. But if the system is shut down hard fsck will run thought all of the local disk listed in the /etc/fstab file to check for a problem, if there is a problem fsck will ask you if you want to fix it.


Single user mode

If something goes wrong with the startup scripts that affects the boot process it is possible to boot into single user mode, make any repairs needed, and then boot into multiuser mode this process involves four steps.

step 1 At the grub boot screen (after restart), select the kernel, press the e key to edit the entry, and the select second line (the line starting with the word kernel)

step 2 select kernel entry, press e again, add key word single to the end of line, press enter, press B to boot into single user mode

step 3 the init file will only go through runlevel 1, type root password press enter

step 4 you will have to change network configuration file and run fsck


Stopping

Here are some basic shutdown commands to cleanly shutting down your system you have to be root or use the sudo command

Shutdown –h now= shutdown the system now and do not reboot

shutdown –r now= shutdown the system now and reboot


File system ext2, ext3, superblocks, i-nodes

A file system organizes data on the storage medium in layers on the disk, ext2 file system has the concept of blocks, i-nodes and directories, ext3 is ext2 file system improved with journaling capabilities, journaling allows fast file system recovery and is the default file systems for Linux. The first block read is the superblock that provides information on the disk shape, free space, and location of the first i-node. The superblock is redundant and placed after every group that contains an i-node and data. The i-node is a control structure every directory gets an i-node that includes information about the files owner, permission, size, and group id, but not the file name. The i-node then points to the files in that directory.


Partitions

Partitioning the hard disk helps to separate data from other data on your hard disk by breaking the hard disk into chunks. Without any partitions, your hard disk is one chunk of empty space where no file system can be stored. There are good reasons to make more than one partition on a hard drive. With multiple partitions, you can easily collect similar data sets into one partition, which keeps everything logically and physically separate. The hard disk for SCSI disks is labeled device/sata drives /dev/sda, /dev/sdb, and so on. SCSI hard drive partitions is represented by an additional number first drive first partition, /dev/sda1, second partition, /dev/sda2 and so on. The commands for partitioning a hard drive are:

1. dmesg | less to find information about the hard drive on your system

2. sudo cfdisk /dev/sda or your disk name could be sdb to find and partition the hard drive

3. while inside cfdick you can follow the prompts to create new partitions when finished tab to write and then exit cfdisk, you are returned to the command line

4. sudo mkfs –t name of file system /dev/sdb number of partition could be 1 through 4 this step must be done for each partition

5. create the mount points new directories using the mkdir name of directory command this is where you are going to mount the partitions

6. sudo mount /dev/sda# (or name and number of disk) name of directory you are mounting to

7. you can then use the df -1 command to check the free space on each partition

CFDisk is a tool that is used to partition a hard disk it is a Linux partition editor, similar to fdisk, but with a different user interface.

The mkfs command makes a new file system on a specified device the command initializes the file system.

The mount command serves to attach the file system found on some device.