You are on page 1of 32

Processes

Each of these operations is called a process A daemon that starts up at boot time A command issue by a regular user A program, such as a cron job, that begins at a specific time A call to the system from an outside source, such as a request to view a Web document Linux allows several processes to work in tandem or to execute simultaneously , true multitasking OS(Linux)

Identifying Processes with PIDs


Linux control each of these processes. As each process starts , Linux assigns it a process ID(PID), a unique number not shared by any other process. Linux can assign the same process ID to another process if the first process either completed or killed. Init is the first process PID=1 and parent of all the processes A user cannot change the PID of a process . The only way a user can change the PID is to start it again or kill the process. For certain process, PID cannt be changed e.g. init(pid=1) or this process can be killed, killing init means rebooting or shuting system. PID is a 16-bit numeric value can reach upto 65536. PPIS (parents process ID)

Identifying Users and Groups by UIDs and GIDs

Processes - UID & GID Real UID At process creation, the real UID identifies the user who has created the process Real GID At process creation, the real GID identifies the current connect group of the user for which the process was created (root user UID=1, first user get the uid=501 by default)

Processes UID & GID

The process initiated by the regular user will receive lower priority or less processor time as its operation is not integral to system performance. Process initiated by root or system will receive higher priority. Modifying Processs Priority The priority of a user processes can be changed directly, the nice value of a process can be changed . (nice value: amount of CPU time allotted to a process) Lower nice value , higher priority Ulimit command can be used to see resource limits.

If you want to place a process ahead of other process, set the nice value higher. Nice value ranges -20 to 20. The default value for most processes is 0. Regular users can increase the nice value(lower the priority) only of their own processes. They cannot decrease the value. Root can decrease the nice value (higher priority) Command is in /bin/nice #nice +5 myfile Lowering priority, now process will take less cpu time # nice -20 make Lower nice value , higher priority

Processes commands
Ps: ps gives a snapshot of the current processes. If you want a repetitive update of this status, use top.
This version of ps accepts several kinds of options.
Unix98 options may be grouped and must be preceeded by a dash.
BSD options may be grouped and must not be used with a dash. GNU long options are preceeded by two dashes.

SIMPLE PROCESS SELECTION Switch Description

-A select all processes


-N negate selection -a select all with a tty except session leaders

-d select all, but omit session leaders


-e select all processes T select all processes on this terminal

a select all processes on a terminal,

including

those of other users

g really all, even group leaders (does nothing w/o SunOS settings) r restrict output to running processes x select processes without controlling ttys & also include system processes

-p select by PID

-s select processes belonging to the sessions given


-t select by tty -u select by effective user ID (supports names)

U select processes for specified users

-f does full listing -j jobs format -l long format

Description of headings
User : username of the process's owner PID : process ID %CPU: the percentage of the cpu time the process has recently used %MEM : the percentage of the memory the process is using Vsz: the virtual size of the process in kilobytes RSS Resident set size(amount of physical memory used)

TTY: Terminal id
Stat : the current status of the process

Status flags

D signifies the process is in disk for shortterm wait I : states the process is idle R : the process is currently running S : process is currently sleeping T : process is stopped Z : process is Zombie( the parent process is died but child process is still running) W : process with no resident pages

Managing foreground & Backgroud processes


Cancelling a foreground process To cancel the process that is currently running enter the key combination: Ctrl-c To suspend a foreground process enter the key combination: Ctrl-z Restarting the suspended process as foreground & background fg lpr -Pps23 bigfile.ps Bg Jobs(to see the list of background running jobs)

To kill a process use the kill command. kill [-signal] process_identifier (PID) Use the ps command if you need to find the PID of a process. Always try to kill a process with a simple kill command. kill process_identifier This is the cleanest way to kill a process and has the same effect as cancelling a process. If this does not work use the -1 (one) signal. kill -1 process_identifier This tells the process to hangup just as though you were logging out. The system will attempt to kill any child processes. As a last resort use the -9 signal: kill -9 process_identifier This will stop the process dead in its tracks but it may leave any child processes still running.

To run a foreground process as a background job:


1. Suspend the foreground process. 2. Enter the bg (background) command to move the process into the background. For example: lpr -Pps23 part[1-8].ps ^Z Stopped bg [1] lpr -Pps23 interface.ps & jobs [1] Running lpr -Pps7 interface.ps This starts a foreground process to print several files. The process is then stopped and the job moved into the background. The state of this job is then checked.

Running processes as background jobs

To run a process in the background as a job and carry on working add an & (ampersand) at the end of the command line. For example: find /usr/man -name *.1 -print > sect1 & [1] 2548 The shell forks a child process to run the command and displays the job number ([n]) and the PID (Process IDentifier) number. The shell prompt returns and you can enter further commands.

nohup Run a command immune to hangups, runs the given COMMAND with hangup signals ignored, so that the command can continue running in the background after you log out. SYNTAX nohup Command [Arg]... `nohup' increases the scheduling priority of COMMAND by 5, this gives a slightly lower priority. `nohup' does not automatically put the command it runs in the background; you must do that explicitly, by ending the command line with an `&'. If standard output is a terminal, it and standard error are redirected so that they are appended to the file `nohup.out'

Nice command
nice - run a program with modified scheduling priority
Syntax:

nice [-increment | -n increment ] command


DESCRIPTION

Run COMMAND with an adjusted scheduling priority. With no COMMAND, print the current scheduling priority. ADJUST is 10 by default. Range goes from -20 (highest priority) to 19 (lowest).

increment : must be in the range 1-19; if not specified, an increment of 10 is assumed. An increment greater than 19 is equivalent to 19. The super-user may run commands with priority higher than normal by using a negative increment such as -10. A negative increment assigned by an unprivileged user is ignored. command : The name of a command that is to be invoked. If command names any of the special builtin utilities, the results are undefined.

Nice (contd..)
Examples nice +13 pico myfile.txt Runs the pico command on myfile.txt with an increment of +13.

Only a privileged user may run a process with lower niceness: $ nice -n -1 command-name

GDM: Gnome Desktop Manager GNOME stands for 'GNU Network Object Model Environment' KDE stands for K desktop environment K means Kool

Managing Users
Useradd command: # usedadd student Used to create new user accounts Owned by the root user File is located in /usr/sbin If logged as root user, command should be within your path Sometimes adduser also works, Linux creates a symbolic link from useradd to adduser

Useradd command:
Su (switch user) su username Useradd command creates a /home/student directory installs student in the /etc/passwd (and /etc/shadow if shadowed passwords were enabled) Entry in the /etc/group file. Places special dot files within that users home directory based on the contents of the /etc/skel directory. Still unable to login until the password is set. Type passwd and the username e.g. passwd student

Removing users
Userdel username e.g. userdel student Command file is placed in /etc/sbin Remove references from /etc/passwd and /etc/shadow But to remove all the files and directories owned by that user Userdel r student

Manually adding user


Create the users home directory Edit the /etc/passwd file make entry Add the user to the /etc/group file. Either add it to an existing group or create one specifically for the user. Set the permissions on all directories by chown and chgrp commands, to set permissions recursively to all subdirectories, use the R option

# chown newownername filename e.g. chown amit abc.txt The chgrp command is used to change the group that has access to files and directories. All files in linux belong to an owner, and a group. The owner is set by the chown command, and the group by the chgrp command. The format is chgrp newgroup filename(s) [options] Create passwd

Copy files located in the /etc/skel diectory to user home directory Include any startup file needed to run upon login in the .bashrc file Create a mail account with the users name in /var/sbin/spool Edit any quota information for that user with the /usr/sbin/edquota command, if quotas are enabled You can customized your shell. Verify the new account by logging

usermod - Modify a user account


usermod [-c comment] [-d home_dir [-m]] The usermod command modifies the system account files to reflect the changes that are specified on the command line. The options which apply to the usermod command are: . usermod [options] LOGIN usermod G others roger [-e expire_date(YYYY-MM-DD)] [-f inactive_time] [-g initial_group] [-G group [,...]] [-l login_name] [-p passwd] [-s shell] [-u uid [-o]] [-L|-U] login

-d home_dir
The user's new login directory. If the -m option is given the contents of the current home directory will be moved to the new home directory, which is created if it does not already exist.

-e expire_date
The date on which the user account will be disabled. The date is specified in the format YYYY-MM-DD.

-g initial_group
The group name or number of the user's new initial login group. The group name must exist. A group number must refer to an already existing group. The default group number is 1.

-G group,[...]
A list of supplementary groups which the user is also a member of. Each group is separated from the next by a comma, with no intervening whitespace. The groups are subject to the same restrictions as the group given with the -g option. If the user is currently a member of a group which is not listed, the user will be removed from the group

-l login_name
The name of the user will be changed from login to login_name. Nothing else is changed. In particular, the user's home directory name should probably be changed to reflect the new login name.

-p passwd
The encrypted password, as returned by crypt(3).

-s shell
The name of the user's new login shell. Setting this field to blank causes the system to select the default login shell.

-u uid
The numerical value of the user's ID. This value must be unique. The value must be non-negative. Values between 0 and 99 are typically reserved for system accounts. Any files which the user owns and which are located in the directory tree rooted at the user's home directory will have the file user ID changed automatically. Files outside of the user's home directory must be altered manually.

#vi /grub/grub.conf #vi /etc/passwd #whereis grub.conf #whatis grub.conf #find name useradd -print

-L
Lock a user's password. This puts a '!' in front of the encrypted password, effectively disabling the password. You can't use this option with -p or -U.

-U
Unlock a user's password. This removes the '!' in front of the encrypted password. You can't use this option with -p or -L.

You might also like