1 / 94

OS Overview

OS Overview. User Program. Traps/ Interrupts. User Libraries. User Level. Kernel Level. System Call Interface. Block Diagram of the System Kernel. Security Interface. Mobility Interface. File System. Process Control system. Inter process Communication. Confidentiality. MIPv4.

paxton
Download Presentation

OS Overview

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. OS Overview .

  2. User Program Traps/ Interrupts User Libraries User Level Kernel Level System Call Interface Block Diagram of the System Kernel Security Interface Mobility Interface File System Process Control system Inter process Communication Confidentiality MIPv4 Buffer Cache Authentication Intra process Communication MIPv6 Integrity character block Scheduler Scheduler VoIP & PTT Support Nonrepudiation Memory Management Device Driver Access Control Availability Hardware Control Hardware .

  3. Algorithm Analysis Notations .

  4. Big O Notation cg(n) f(n) k Definition:A theoretical measure of the execution of an algorithm, usually the time or memory needed, given the problem size n, which is usually the number of items. Informally, saying some equation f(n) = O(g(n)) means it is less than some constant multiple of g(n). Formal Definition: f(n) = O(g(n)) means there are positive constants c and k, such that 0 ≤ f(n) ≤ cg(n) for all n ≥ k. The values of c and k must be fixed for the function f and must not depend on n. .

  5. Big ω Notation f(n) cg(n) k Definition:A theoretical measure of the execution of an algorithm, usually the time or memory needed, given the problem size n, which is usually the number of items. Informally, saying some equation f(n) = ω (g(n)) means g(n) becomes insignificant relative to f(n) as n goes to infinity. Formal Definition: f(n) = ω (g(n)) means that for any positive constant c, there exists a constant k, such that 0 ≤ cg(n) < f(n) for all n ≥ k. The value of k must not depend on n, but may depend on c. .

  6. Big Θ Notation c2g(n) f(n) c1g(n) k Definition:A theoretical measure of the execution of an algorithm, usually the time or memory needed, given the problem size n, which is usually the number of items. Informally, saying some equation f(n) = Θ (g(n)) means it is within a constant multiple of g(n). The equation is read, "f of n is theta g of n". Formal Definition: f(n) = Θ (g(n)) means there are positive constants c1, c2, and k, such that 0 ≤ c1g(n) ≤ f(n) ≤ c2g(n) for all n ≥ k. The values of c1, c2, and k must be fixed for the function f and must not depend on n. .

  7. Process Management .

  8. A process is an entity which is created by the operating system and consists of a sequence of bytes which is interpreted by the CPU as • Machine instruction. • Data • Stack. • Many processes appear to execute simultaneously as the kernel schedules them for execution and several processes may be an instance of one program. In UNIX fork is used to create a process. Process Definition .

  9. Process State & Transition User Running Trap/interrupt return Interrupt/Interrupt Return Kernel Schedule Process sleep Sleep Ready to run Wakeup .

  10. Process Structure Process consists of 3 regions. Region is a contiguous area of the virtual address space .

  11. Per process region table U Area Region table Process table Data structure for a process text data stack memory Per process region table allows independent processes to share regions. .

  12. File System .

  13. The collection of files and file management structures on a physical or logical mass storage device, such as a diskette or disk • the way the files are organized on the disk and the methods and data structures that an operating system uses to keep track of files on a disk or partition. • A data structure that translates the logical (files, directories) structure into physical (sector); it helps both computers and users to locate files. File System Definition .

  14. / File System Architecture for UNIX bin etc user unix dev tty01 tty00 mike jim y z x .

  15. File System Layout Boot block Super block Inode list Data Blocks Boot Block : first sector, contains bootstrap code to initialize the operating system Super Block : how many file it can store, where to find free space Inode List : The list of inode in the file system. Each Inode may represent a file or a directory. Data Blocks : The list of data blocks to carry the files information. .

  16. File System Data Structure User File Descriptor File Table Inode Table User File Descriptor: For each process. identify all open files for specific process File table: Shared between all processes in the system . Contains how many bytes read or written, access rights allowed for the file Inode Table: access rights and file blocks location .

  17. Intra process communication .

  18. signals Kill (pid, SIGSTOP) P1 P2 • Signals are limited form of IPC that are used to notify a process that a given event has taken place. • Each signal has a unique positive integer representing it as well as a symbolic name (that is usually defined in the file /usr/include/signal.h. • Amount of information that can be conveyed via a signal is very limited (basically only the signal number). .

  19. signals (continue) • When a signal interrupts a process, the signal is handled as follows: • Ignore the signal. • Catch the signal. • default action apply. .

  20. Sending Signals • Using the keyboard:the Ctrl-C key causes the operating system to send a SIGINT signal to the running process • From the command line: kill -INT 3333 • Using system calls: • #include <unistd.h> /* standard unix functions, like getpid() */ • #include <sys/ types.h> /* various type definitions, like pid_t */ • #include <signal.h> /* signal name macros, and the kill() prototype */ • /* first, find my own process ID */ • pid_t my_pid = getpid(); /* now that i got my PID, send myself the SIGSTOP signal. */ • int rc = kill(my_pid, SIGSTOP); • if (rc != 0) /* unsuccessful */ • { • printf ("The \"kill\" system call failed with rc: %d\n", rc); • } .

  21. Catching Signals #include <stdio.h> /* standard I/O functions */ #include <unistd.h> /* standard unix functions, like getpid() */ #include <sys/types.h> /* various type definitions, like pid_t */ #include <signal.h> /* signal name macros, and the signal() prototype */ /* The signal handler definition. */ void sigintHandler(int sig_num) { /* Register signal handler for SIGINT next time */ signal(SIGINT, sigintHandler); /* Print the message */ printf ("Don't you dare interrupt me\n"); } /* The main function. */ int main (int argc, char* argv[]) { /* Register signal handler for SIGINT */ signal(SIGINT, sigintHandler); /* Go into an infinite loop */ for ( ;; ) pause(); } .

  22. pipes Fd[1] Fd[0] write read P1 P2 Pipes allows transfer of stream of data between processes in a first-in-first-out manner (FIFO), and also allow synchronization of process execution. .

  23. Pipes (continue) #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <unistd.h> int main() { int pfds[2]; char buf[30]; if (pipe(pfds) == -1) { perror("pipe"); exit(1); } printf ("writing to file descriptor #%d\n", pfds[1]); write(pfds[1], "test", 5); printf ("reading from file descriptor #%d\n", pfds[0]); read(pfds[0], buf, 5); printf ("read \"%s\“ \n", buf); } .

  24. message queues msgrcv msgsnd P1 P2 Message queues allows transfer of user defined messages between processes in a first-in-first-out manner (FIFO), and they also allow synchronization of process execution. .

  25. #include <sys/types.h> • #include <sys/ipc.h> • #include <sys/msg.h> • #define MSGKEY 75 • struct msgform{ • long msgtype; • char mtext [256]; • } • main () • { • struct msgform msg; • int msgid, pid; • pid = getpid (); • msg.mtext [0] = pid; • msg.mtype = 1; • msgid = msgget (MSGKEY,0777); • msgsend (msgid, &msg,sizeof (int),0); • msgrcv (msgid, &msg,256,pid,0); • } msgsnd & msgrcv example .

  26. Shared memory example (continue) Shared memory strncpy strncpy P1 P2 a segment of memory that is shared between processes no synchronization of processes is provided. .

  27. #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/shm.h> #define SHM_SIZE 1024 /* make it a 1K shared memory segment */ int main (int argc, char *argv[]) { key_t key; int shmid; char *data; int mode; /* make the key: */ if ((key = ftok ("shmdemo.c", 'R')) == -1) { perror("ftok"); exit(1); } Shared memory example .

  28. /* connect to (and possibly create) the segment: */ if ((shmid = shmget(key, SHM_SIZE, 0644 | IPC_CREAT)) == -1) { perror ("shmget"); exit(1); } /* attach to the segment to get a pointer to it: */ data = shmat (shmid, (void *)0, 0); if (data == (char *)(-1)) { perror ("shmat"); exit(1); } /* read or modify the segment, based on the command line: */ strncpy (data, argv[1], SHM_SIZE); printf ("segment contains: \"%s\"\n", data); /* detach from the segment: */ if (shmdt(data) == -1) { perror ("shmdt"); exit(1); } return 0; } Shared memory (continue) .

  29. sockets Fd[1] Fd[0] write read P1 P2 Sockets are used for inter and intra process communication. It is based on TCP or UDP, and also allow synchronization of process execution. .

  30. UDP Socket system calls for client/server Client Side Server Side socket socket connect bind write read read write close close .

  31. Conceptual OS Data Structure for UDP socket File Descriptor Table One per process stdin stdout stderr .

  32. TCP Socket system calls for client/server Client Side Server Side socket socket connect bind write listen read accept close read write close .

  33. Conceptual OS Data Structure for TCP socket File Descriptor Table One per process stdin stdout stderr .

  34. #include <sys/types.h> #include <sys/socket.h > #include <netinet/in.h> #include <arpa/inet.h > #include <netdb.h > #include <stdio.h> #include <unistd.h> /* close() */ #include <string.h> /* memset() */ #define LOCAL_SERVER_PORT 1500 #define MAX_MSG 100 int server (char *protocol,int argc, char *argv[]) { int sd, rc, n, cliLen; struct sockaddr_in servAddr; char msg[MAX_MSG]; /* socket creation */ if (strcmp (protocol, ”udp”) == 0) sd =socket (AF_INET, SOCK_DGRAM, 0); else sd =socket (AF_INET, SOCK_STREAM, 0); /* bind local server port */ servAddr.sin_family = AF_INET; servAddr.sin_addr.s_addr = htonl(INADDR_ANY); servAddr.sin_port = htons(LOCAL_SERVER_PORT); rc = bind (sd, (struct sockaddr *) &servAddr,sizeof(servAddr)); if (strcmp (protocol, ”udp”) != 0) listen (sd,5); return sd; } UDP/TCP Server .

  35. #include <sys/types.h> #include <sys/socket.h > #include <netinet/in.h> #include <arpa/inet.h > #include <netdb.h > #include <stdio.h> #include <unistd.h> /* close() */ #include <string.h> /* memset() */ #define REMOTE_SERVER_PORT 1500 int client (int protocol,int argc, char *argv[]) { int sd, rc, i; struct sockaddr_in sin; struct hostent *h; /* get server IP address*/ h = gethostbyname(argv[1]); sin.sin_family = h->h_addrtype; // AF_INET memcpy ((char *) &sin.sin_addr.s_addr, h->h_addr_list[0], h->h_length); sin.sin_port = htons(REMOTE_SERVER_PORT); /* socket creation */ if (strcmp (“udp”, protocol) == 0) sd = socket(AF_INET,SOCK_DGRAM,0); else sd = socket(AF_INET,SOCK_STREAM,0); if ((rc = connect (sd, (struct sockaddr *) &sin, sizeof(sin))<0) return -1; return sd; } UDP/TCP Client .

  36. /* server infinite loop */ • int main (int argc, char *argv[]) • ( • int sd =0, cliLen; • struct sockaddr_in cliAddr; • sd = server (“udp”, argc, argv); • while(1) { /* init buffer */ • memset(msg,0x0,MAX_MSG); /* receive message */ • cliLen = sizeof(cliAddr); • n = recvfrom(sd, msg, MAX_MSG, 0, • (struct sockaddr *) &cliAddr, &cliLen); • if (n<0) { • printf("%s: cannot receive data \n",argv[0]); • exit (-1); • } /* print rcv message */ • print ("%s: from %s:UDP%u : %s \n", • argv[0],inet_ntoa(cliAddr.sin_addr), • ntohs(cliAddr.sin_port),msg); • }/* end of server infinite loop */ • return 0; • } UDP Server .

  37. Inter process communication .

  38. Inter process communication protocols • TCP – Transport Communication Protocol. • UDP - User Defined Protocol. • IP4 - Internet Protocol version 4. • IP6 - Internet Protocol version 6. .

  39. Application (MIPv4) Kernel Transport (UDP,TCP) Internet Protocol (MIP6,MIPv4,IP4,IP6) Data Link Layer Physical Layer Protocol Stack .

  40. TCP Protocol Procedure .

  41. TCP- Transport Communication Protocol • Byte stream service with no structure. • Full Duplex. • Connection Oriented. • Reliable Service. .

  42. User B User A TCP:SYNC – (port 5060) TCP:SYNC+ACK – (port 5060) TCP:ACK – (port 5060) TCP Connection Opened .

  43. User A User B TCP:FIN – (port 5060) TCP:ACK – (port 5060) Connection Closed TCP:FIN – (port 5060) TCP:ACK – (port 5060) TCP Connection Closed .

  44. TCP Sliding Window Initial window Window slides A sliding window protocol with 8 packets in the window. The window slides so that packet 9 can be sent when an acknowledgment has been received for packet 1. Only non acknowledged packets are retransmitted. .

  45. TCP Positive Acknowledgement User A User B Send Packet 1 Send Packet 2 Send Packet 3 Recv Packet 1 Send ACK1 Recv Packet 2 Send ACK 2 Recv Packet 3 Send ACK 3 Recv Ack 1 Recv Ack 2 Recv Ack 3 .

  46. UDP Protocol .

  47. User Datagram Protocol (UDP) p1 p1 p2 p2 Host:: x2.y2.z2.w2 Host:: x1.y1.z1.w1 p3 p3 Multiple applications distinguished by port numbers Multiple applications distinguished by port numbers The UDP protocol provides an unreliable connectionless delivery service using IP to transport messages between machines. It uses IP to carry messages, but adds the ability to distinguish among multiple destinations within the given host computer .

  48. UDP Header Source Port Destination Port UDP Checksum UDP Message Length Data .

  49. UDP Checksum = Calculate Checksum Received Packet Checksum If changed or not Verify the integrity of the packet .

  50. IP4 Protocol .

More Related