Upload
julius-carroll
View
221
Download
0
Embed Size (px)
Citation preview
Introduction to UNIXRoad Map:1. UNIX Structure2. Components of UNIX3. Process Structure4. Shell & Utility Programs5. Using Files & Directories6. Compiling and Running C Programs in UNIX
UNIX Structure
Multiuser : Several users can use a UNIX system at the same time.
Multitasking : Can run multiple processes at the same time.
Hardware
UNIX KernelPOSIX system call API
P1 P2 PN…
Components of UNIX
1. Kernel + POSIX system call API◦ Covered in OS
2. Shell (program to launch other programs)
3. Standard utility programs ◦(cp, mv, ls, cat, …)
4. System configuration files◦(/etc/vfstab,…)
Process Structure
init
login login (/bin/login)
login
shell (/bin/sh)
ls wc cat
Other user programs
Logging In/Out
Login : user1Password: 123
% command get a shell prompt% command get another shell prompt% exit logout & terminate shell
Shell
a.k.a command line interpreter
Getting help on UNIX% man ls% man man
while(1)1. prompt the user for the next command2. Read the next command3. Parse the command line4. Launch the programs (fork, exec)5. Wait until the programs terminate
(waitpid)end
Running utility programsMost utility programs are located
in /usr/binBasic form of a UNIX command is
% command [-options] [arguments]
Ex:
% ls
% ls –a
% ls –al
% ls BIM322
% ls –al BIM322
% clear cleans the screen
Aborting a shell command: press ^C
UNIX has a tree-like hierarchical directory structure.
When you login, login utility reads your home directory from /etc/passwd and changes your current directory to be your home directory.
Using Files & Directories
tmp bin lib usr etc home export dev
include bin local
bin
Directories1. % pwd print working directory2. % cd BIM322 change current directory % cd .. change to parent % cd / change to root % cd /usr/local absolute path specification % cd % cd ~ takes you to your home % cd ~cakinlar directory3. % ls –al list directory content4. % mkdir AA create a new directory5. % rmdir AA remove a directory
Files1. % touch file1 create an empty file2. % cp file1 file2 copy files3. % mv file1 /tmp move file to directory % mv file1 file3 move file to a new file % mv AA /tmp can also move directories4. % rm file1 remove a file5. % find . –name file1 find a file6. % cat file1 view all at once7. % more file1 page by page8. % head file1 first … lines9. % tail file1 last … lines
Compiling and Running C Programs in UNIX1. Open an editor, type your ‘Hello world’
program.
2. % gcc first.c outputs a.out3. % ./a.out or % ./a4. % gcc –o first first.c5. % ./first
// first.cinclude <stdio.h>int main(int argc, char *argv[]){ int i; for(i=0; i<argc; i++) printf("arg[%d]: %s\n", i, argv[i]);} //end-main