ITBP 315 - Operating Systems Fundamentals Lab 5 - Process Management
ITBP 315 - Operating Systems Fundamentals Lab 5 - Process Management
Procedure:
Wildcards
Type
$ ls *list
This will list all files in the current directory ending with ....list
$ ls ?list
Filename conventions
A directory is merely a special type of file. So the rules and conventions for
naming files apply also to directories.
For example, all files consisting of C code may be named with the ending .c, for
example, prog1.c . Then in order to list all files containing C code in your home
directory, you need only type ls *.c in that directory.
1
On-line Manuals
There are on-line manuals which gives information about most commands. The
manual pages tell you which options a particular command can take, and how
each option modifies the behaviour of the command. Type man command to
read the manual page for a particular command.
For example, to find out more about the wc (word count) command, type
$ man wc
Alternatively
$ whatis wc
gives a one-line description of the command, but omits any information about
options etc.
You will see that you now get lots of details about the contents of your
directory, similar to the example below.
2
Changing access rights
Only the owner of a file can use chmod to change the permissions of a file. The
options of chmod are as follows
Symbol Meaning
u user
g group
o other
a all
r read
w write (and delete)
x execute (and access directory)
+ add permission
- take away permission
3
For example, to remove read write and execute permissions on the file biglist
for the group and others, type
$ ps
Some processes take a long time to run and hold up the terminal.
Backgrounding a long process has the effect that the UNIX prompt is returned
immediately, and other tasks can be carried out while the original process
continues executing.
To background a process, type an & at the end of the command line. For
example, the command sleep waits a given number of seconds before
continuing. Type
$ sleep 10
This will wait 10 seconds before returning the command prompt $. Until the
command prompt is returned, you can do nothing except wait.
4
To run sleep in the background, type
$ sleep 10 &
[1] 6259
The & runs the job in the background and returns the prompt straight away,
allowing you do run other programs while waiting for that one to finish.
The first line in the above example is typed in by the user; the next line,
indicating job number and PID, is returned by the machine. The user is be
notified of a job number (numbered from 1) enclosed in square brackets,
together with a PID and is notified when a background process is finished.
Backgrounding is useful for jobs which will take a long time to complete.
$ sleep 100
You can suspend the process running in the foreground by holding down the
[control] key and typing [z] (written as ^Z) Then to put it in the background,
type
$ bg
$ jobs
$ fg $jobnumber
5
For example, to restart sleep 100, type
$ fg $1
Killing a process
To kill a job running in the foreground, type ^C (control c). For example, run
$ sleep 100
^C
$ kill $jobnumber
$ kill $4
To check whether this has worked, examine the job list again to see if the
process has been removed.
ps (process status)
6
PID TT S TIME COMMAND
20077 pts/5 S 0:05 sleep 100
21563 pts/5 T 0:00 netscape
21873 pts/5 S 0:25 nedit
$ kill 20077
and then type ps again to see if it has been removed from the list.
$ kill -9 20077
Summary
* match any number of characters
? match one character
man command read the online manual page for a command
whatis command brief description of a command
apropos keyword match commands with keyword in their man pages
7
Assignment: (Due date: 1 week)
Source: http://www.ee.surrey.ac.uk/Teaching/Unix/index.html