Presentation is loading. Please wait.

Presentation is loading. Please wait.

Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process System Process and init.

Similar presentations


Presentation on theme: "Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process System Process and init."— Presentation transcript:

1 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process System Process and init Even though no one may be using the system, a number of processes keep running all the time. These processes are spawned during system startup by init (PID 1), the parent of the login shell. The ps –e command lists them all. When running the ps –e command, the system processes that have no controlling terminal are easily identified by the ? in the TTY column (tty is a Unix command that prints to standard output the name of the file connected to standard input. The name of the program comes from teletypewriter, abbreviated "TTY".

2 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process System Process and init A process that is disassociated from the terminal can neither write to the terminal nor read from it. Such processes are known as daemons. Many of these daemons are actually sleeping (a process state) and wake up only when they receive input.

3 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process System Process and init Daemons do important work for the system. The lpsched daemon controls all printing activity. The sendmail handles both your incoming and outgoing mail The TCP/IP network won’t run FTP and TELNET without the inetd daemon. cron is a time-based scheduling service. cron is driven by a crontab, a configuration file that specifies shell commands to run periodically on a given schedule.

4 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process The Process Creation Mechanism How is the process created? A process can only be created by another process, and the creation mechanism involves three phases: Fork Exec Wait

5 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process The Process Creation Mechanism Fork Forking creates a process by creating a copy of the existing process. The new process has a different PID, and the process that created it becomes its parent. Otherwise the parent and the child have the same process image. If the child does not do an exec, both parent and child would continue to execute the same code from the point forking was invoked.

6 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process The Process Creation Mechanism Exec Forking creates a process, but it is not enough to run a new program. To do that, the fork child needs to overwrite its own image with the code and data of the new program. This mechanism is called exec, and the child process is said to exec a new program. No new process is created here; the PID and PPID of exec’d process remain unchanged.

7 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process The Process Creation Mechanism Wait while the child is executing a new program, the parent normally waits for the child to die. It then picks up the exit status of the child before it does something else.

8 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process The Process Creation Mechanism Example When we run cat from the shell, the shell first forks another shell process. The newly forked shell then overlays itself with the executable image of cat which then starts to run. The parent (original) shell waits for cat to terminate and then picks up the exit status of the child. This is a number returned by the child to the kernel, and has great significance in both shell programming and systems programming (aims to produce software which provides services to the computer hardware).

9 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process Inherited Process Attributes When a process is forked and exec’d, the new program has a different PID and PPID then its parent. However, it inherits most of the environment of its parent. The important attributes that are inherited are: The real UID and real GID of the process These represent the UID and GID of the user running the program The effective UID and effective GID of the process These are generally the same as the real ones, but some processes behave differently.

10 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process Inherited Process Attributes Why does every process have two UIDs and two GIDs (real and effective)? When running the cat command, a non-privileged user can not use cat to open a file that is readable only by root.

11 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process Inherited Process Attributes Why does every process have two UIDs and two GIDs (real and effective)? {apache:~} ls -l /bin/cat /usr/bin/passwd -r-xr-xr-x 1 root bin 10260 Jan 22 2005 /bin/cat -r-sr-sr-x 1 root sys 27220 Jan 22 2005 /usr/bin/passwd Notice the bit marked s in the permissions field of passwd; this bit is called the set-user-id (SUID), changes the normal ownership scheme. The passwd command must run as it’s executed by the superuser; otherwise file /etc/shadow will not be modified.

12 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process Inherited Process Attributes {apache:~} x=5 {apache:~} bash {apache:~} echo $x {apache:~} {apache:~} exit {apache:~} x=5; export x {apache:~} bash {apache:~} echo $x 5 {apache:~} x=10; echo $x 10 {apache:~} exit {apache:~} echo $x 5

13 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process When you Can’t Use a Separate Process ($echo “You have not keyed in 3 arguments” ; exit) this sequence meant to terminate the current shell; but it will not. Commands grouped in () are run in a sub-shell. { echo “You have not keyed in 3 arguments” ; sleep2; exit ;} Commands grouped within {} are executed in the current shell.

14 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process Process States and Zombies Running: At any instant of time, a process is in a particular state. A process after creation is in the runnable state before it actually runs (state running). Sleeping: While the process is running, it may invoke a disk I/O operation. The process then has nothing to do except wait for the I/O to complete. The process then moves to the sleeping state to be woken up when the I/O operation is over. Suspended: The process can also be suspended by pressing, usually, [Ctrl-z].

15 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process Process States and Zombies Zombie: Process whose parents don’t wait for their death move to zombie state. When the process dies, its parent picks up the child’s exit status (the reason for waiting) from the process table and frees up the process table entry. However, when the parent doesn’t wait (but is still alive), the child turns into a zombie. A zombie is a harmless dead child that reserves the process table slot. When the parent dies before the child, the child then becomes an orphan and kernel makes init the parent of all the orphans.

16 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process Process States and Zombies {apache:~} ps -l -u kkhan F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 0 S 127603 23589 23569 0 50 20 ? 317 ? pts/120 0:00 bash 0 S 127603 23569 23566 0 40 20 ? 184 ? pts/120 0:00 ksh 0 S 127603 23566 23550 0 40 20 ? 1049 ? ? 0:00 sshd 0 O 127603 27275 23589 0 60 20 ? 170 pts/120 0:00 ps O – Running on the CPU S – Sleeping, process is waiting for an event R – Runnable. The process simply needs to be selected for running T – Suspended. User pressed [Ctrl-z] Z – Zombie. Parent didn’t wait for the death of the child

17 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – Networking Tools TCP/IP It is a set of networking protocols built into the UNIX kernel. These protocols define a set of rules that each machine must comply with to communicate with another machine in the network. The term TCP/IP expands to Transmission Control Protocol/Internet Protocol, but is actually a collection of several protocols, which includes the TCP and IP protocols.

18 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – Networking Tools TCP/IP It is independent of hardware and operating system. Key features include: Delivery of Data in multiple packets Complete reliability of transmission with full error control

19 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – Networking Tools TCP/IP It is packet-switching system there is no dedicated connection between sender and receiver data is broken in packets, and each packet is provided with a header the header contains the sequence number and checksum determining the exact information in the packet. packets are put inside envelopes, the sender’s and recipient's addresses are written on them, and the packets are sent on their way.

20 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – Networking Tools TCP/IP It is packet-switching system as the packets travel along a vast network like the Internet, they encounter routers everywhere Routers are special computers or intelligent devices that look at the envelope addresses and then determine the most efficient route each packet has to take to move closer to its destination. Because of the load on the network varies constantly, packets may move along different routes and arrive out of order. They are reassembled in the correct order from the information provided in them.

21 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – Networking Tools TCP/IP It is packet-switching system before reassembly, the checksum of each packet is calculated and checked with the number that has been sent in the packet. If the checksums don’t match, the packet is corrupted and has to be resent. Hostname and IP address In a network, computers are known as hosts and identified by their hostnames. These names are unique throughout the network. $ hostname apache (host name) apache.utdallas.edu (FQDN – fully qualified domain name)

22 second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – Networking Tools TCP/IP Every networked host is also assigned an IP address. This is a set of four dot-delimited numbers called (octets). The host apache might have this address: 129.110.16.9 The maximum value of each octet is 255 The IP address of a host is also unique in that network. On the Internet, however, hosts have unique IP addresses and FQDNs. TCP/IP applications can address a host using either form as an identifier.


Download ppt "Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Process System Process and init."

Similar presentations


Ads by Google