130 likes | 297 Views
Introduction to UNIX. Road Map: UNIX Structure Components of UNIX Process Structure Shell & Utility Programs Using Files & Directories Compiling and Running C Programs in UNIX. UNIX Structure. …. P 1. P 2. P N.
E N D
Introductionto UNIX Road Map: UNIX Structure Components of UNIX ProcessStructure Shell & Utility Programs Using Files & Directories CompilingandRunning C Programs in UNIX
UNIX Structure … P1 P2 PN • Multiuser: Severalusers can use a UNIX system at thesame time. • Multitasking : Can runmultipleprocesses at thesame time. POSIX systemcall API UNIX Kernel Hardware
Components of UNIX • Kernel + POSIX systemcall API • Covered in OS • Shell (program tolaunchotherprograms) • Standardutilityprograms • (cp, mv, ls, cat, …) • Systemconfigurationfiles • (/etc/vfstab,…)
ProcessStructure init login(/bin/login) login login shell(/bin/sh) ls wc cat Otheruserprograms
LoggingIn/Out Login : user1 Password: 123 %command get a shellprompt %command getanothershellprompt % exit logout & terminateshell
Shell a.k.acommandlineinterpreter • Gettinghelp on UNIX % manls % manman • while(1) • prompt the user for the next command • Read thenextcommand • Parsethecommandline • Launchtheprograms (fork, exec) • Waituntiltheprogramsterminate (waitpid) • end
Runningutilityprograms • Mostutilityprogramsarelocated in /usr/bin • Basic form of a UNIX command is % command [-options] [arguments] Ex: % ls % ls –a % ls –al % ls BIM322 % ls –al BIM322 % clear cleansthescreen • Aborting a shellcommand: press^C
Using Files & Directories • UNIX has a tree-likehierarchicaldirectorystructure. • Whenyoulogin, loginutilityreadsyourhomedirectoryfrom/etc/passwdandchangesyourcurrentdirectoryto be yourhomedirectory. tmp bin libusretchomeexport dev include bin local bin
Directories • % pwdprintworkingdirectory • % cd BIM322 changecurrentdirectory % cd .. changetoparent % cd / changetoroot % cd /usr/localabsolutepathspecification % cd % cd ~ takesyoutoyourhome % cd ~cakinlardirectory • % ls –al listdirectorycontent • % mkdir AA create a newdirectory • % rmdir AA remove a directory
Files • % touch file1 create an empty file • % cp file1 file2 copyfiles • % mv file1 /tmpmove file todirectory % mv file1 file3 move file to a new file % mv AA /tmpcan alsomovedirectories • % rm file1 remove a file • % find . –name file1 find a file • % cat file1 viewall at once • % more file1 pagebypage • % headfile1 first … lines • % tailfile1 last… lines
CompilingandRunning C Programs in UNIX • Open an editor, typeyour ‘Helloworld’ program. • % gccfirst.c outputsa.out • % ./a.outor % ./a • % gcc –o firstfirst.c • % ./first // first.c include <stdio.h> int main(intargc, char *argv[]){ int i; for(i=0; i<argc; i++) printf("arg[%d]: %s\n", i, argv[i]); } //end-main