Unix

764 views

Published on

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
764
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Unix

  1. 1. Introduction to UNIX Ke Liu http://www.cs.binghamton.edu/~kliu/cs350/ [email_address]
  2. 2. Topics. <ul><li>Logging in. </li></ul><ul><li>Unix Shells and useful shell commands. </li></ul><ul><li>File System in Unix. </li></ul><ul><li>Program, Process and Process control. </li></ul><ul><li>Inter-process communication. </li></ul><ul><li>Compiling and debugging C programs. </li></ul><ul><li>Editors. </li></ul>
  3. 3. UNIX <ul><li>UNIX is multi-user and multi-tasking operating system. </li></ul><ul><li>Multi-tasking: Multiple processes can run concurrently. </li></ul><ul><li>Example, different users can read mails, copy files, and print all at once. </li></ul>
  4. 4. Logging In <ul><li>Enter login name and password ! </li></ul><ul><li>System password file: /etc/passwd (usually). </li></ul><ul><li>You can change password using the command: passwd. </li></ul>
  5. 5. Shell <ul><li>After a successful login, the shell program is run. The default shell of bingsuns: tcsh </li></ul><ul><li>bingsun2% ps </li></ul><ul><li>PID TTY TIME CMD </li></ul><ul><li>2159 pts/2 0:00 tcsh </li></ul><ul><li>Shell is a command line interpreter that reads user commands and executes them. </li></ul>
  6. 6. Unix Shells <ul><li>Common Shells: Bourne shell, the C shell, and the Korn shell. </li></ul><ul><li>The shell on bingsuns is tcsh (tc shell). </li></ul><ul><li>Users can switch between shells, using the commands bash, csh, ksh, sh. </li></ul><ul><li>Control D (^d) to return back to original shell, or just use the command: exit. </li></ul>
  7. 7. Some shell commands <ul><li>Most Important command: man (manual pages). </li></ul><ul><li>Help: unix commands, C functions. </li></ul><ul><li>Usage: man <command/function> </li></ul><ul><li>Try “man man” ! </li></ul><ul><li>Example: </li></ul><ul><li>man ls, man passwd, man printf. </li></ul>
  8. 8. Some shell commands (cont’) <ul><li>pwd: working directory (/u0/users/2/kliu1). </li></ul><ul><li>ls: list contents of directory </li></ul><ul><li>mkdir <dir-name>: make directory </li></ul><ul><li>rmdir <dir-name>: remove an empty directory </li></ul><ul><li>rm –r <dir-name>: remove a directory with all the contents </li></ul><ul><li>cd <directory>: change directory, ~/ means your home directory </li></ul><ul><li>cp <source> <target>: copy command. </li></ul>
  9. 9. Some shell commands (cont’) <ul><li>chmod <mode> <filename>: change mode of a file/directory </li></ul><ul><li>ls –l <directory or filename>: long list with details </li></ul><ul><li>9 permission bits: d r w x r w x r w x </li></ul><ul><li>3 categories: user/group/all. </li></ul><ul><li>Permissions: read/write/execute (r/w/x). </li></ul><ul><li>E.g.: mode= 644 means r w _ r_ _ r _ _ </li></ul><ul><li>command: chmod 644 <filename> </li></ul><ul><li>first 3 bits for user. Next group. Next all others. </li></ul>
  10. 10. Some shell commands (cont’) <ul><li>rm <option> <filename>: remove files </li></ul><ul><li>e.g.: rm –fr directory/filename </li></ul><ul><li>mv <old> <new>: change the name of a file </li></ul><ul><li>Pipes: Connect the stdout of one command with the stdin of another command </li></ul><ul><li> e.g.: ls -l | more or ls –l | less </li></ul>
  11. 11. File System <ul><li>Hierarchical arrangement of files and directories. </li></ul><ul><li>Top level: root or / </li></ul><ul><li>e.g.: cd / </li></ul><ul><li>. Current directory, .. One level higher directory </li></ul><ul><li>e.g.: cd . No change for it is current directory </li></ul><ul><li>or cd .. Change to parent directory. </li></ul>
  12. 12. File System (cont’) <ul><li>Pathname: absolute and relative. </li></ul><ul><li>Absolute pathname: /u0/users/2/kliu1 </li></ul><ul><li>Relative pathname: abc. </li></ul>
  13. 13. Editors. <ul><li>Different editors: emacs, pico, vi </li></ul><ul><li>emacs <filename> </li></ul><ul><li>pico <filename> </li></ul><ul><li>vi <filename> </li></ul>
  14. 14. The easiest editor: pico or nano <ul><li>pico <filename> </li></ul><ul><li>Full screen editor </li></ul><ul><li>Help on the bottom of the screen </li></ul><ul><li>The nano is an extension to the pico </li></ul>
  15. 15. Basic operations in pico <ul><li>Ctrl + v : to move page down </li></ul><ul><li>Ctrl + y : to move page up </li></ul><ul><li>Ctrl + o : to save the current buffer </li></ul><ul><li>Ctrl + x : to exit with or without saving </li></ul><ul><li>Ctrl + g : to get help </li></ul><ul><li>Ctrl + r : to open a file </li></ul><ul><li>Ctrl + w : to find a string in the current buffer </li></ul><ul><li>Ctrl + c : to get the current position in the buffer </li></ul>
  16. 16. Program & Process <ul><li>Program is an executable file that resides on the disk. </li></ul><ul><li>Process is an executing instance of a program. </li></ul><ul><li>A Unix process is identified by a unique non-negative integer called the process ID. </li></ul><ul><li>Check process status using the “ps” command. </li></ul>
  17. 17. Foreground/background processes <ul><li>A program run using the ampersand operator “&” creates a background process. </li></ul><ul><li>E.g.: </li></ul><ul><li>bingsun2% back & </li></ul><ul><li>otherwise it creates a foreground process. </li></ul><ul><li>E.g.: </li></ul><ul><li>bingsun2% back </li></ul>
  18. 18. Foreground/background processes <ul><li>Only 1 foreground process for each session. Multiple background processes. </li></ul><ul><li>Where are background processes used? </li></ul><ul><li>All system daemons, long user processes, etc. </li></ul><ul><li>e.g. printer-daemon process or mailer-daemon process. </li></ul><ul><li>These processes are always running in background. </li></ul><ul><li>Pine is foreground process. </li></ul>
  19. 19. Process Status <ul><li>bingsun2% back & </li></ul><ul><li>[1] 16488 the process id assigned by system </li></ul><ul><li>bingsun2% ps </li></ul><ul><li>PID TTY TIME CMD </li></ul><ul><li>1973 pts/39 0:01 tcsh </li></ul><ul><li>16488 pts/39 0:00 back </li></ul>
  20. 20. How to stop a process? <ul><li>Foreground processes can generally be stopped by pressing CONTROL C (^C). </li></ul><ul><li>Background processes can be stopped using the kill command. </li></ul><ul><li>Usage: kill SIGNAL <process id list> </li></ul><ul><li>kill -9 <process id list> (-9 means no blocked) </li></ul><ul><ul><li>Or kill <process id list>. </li></ul></ul><ul><li>If a foreground process is not stopping by ^C, you can open another session and use the kill command. </li></ul>

×