Spread Knowledge

CS604 - Operating Systems - Lecture Handout 11

User Rating:  / 0
PoorBest 

Related Content: CS604 - VU Lectures, Handouts, PPT Slides, Assignments, Quizzes, Papers & Books of Operating Systems

Summary

  • More on the use of FIFOs in a program
  • Example code for a client-server model
  • A few UNIX/Linux process management commands

Use of FIFOs

We continue to discuss the API for using FIFOs for IPC between UNIX/Linux processes.
We call these processes client and server. The server process creates two FIFOs, FIFO1 and FIFO2, and opens FIFO1 for reading and FIFO2 for writing. The client process opens FIFO1 for writing and FIFO2 for reading. The client process writes a message to the server process and waits for a response from the server process. The server process reads the message sent by the client process and displays it on the monitor screen. It then sends a message to the client through FIFO2, which the client reads and displays on the monitor screen. The server process then closes the two FIFOs and terminates. The client, after displaying server’s message, deletes the two FIFOs and terminates. The protocol for the client-server interaction is shown in Figure 10.1.

Use of FIFOs

The codes for the server and client processes are shown in Figure 10.2 and Figure 10.3, respectively.

Code for the server process

Figure 10.2 Code for the server process

Code for the client process

Figure 10.3 Code for the client process

In the session shown in Figure 10.4, we show how to compile and run the clientserver software. We run the server process first so it could create the two FIFOs to be used for communication between the two processes. Note that the server process is run in the background by terminating its command line with an ampersand (&).

Compilation and execution of the client-server software

UNIX/Linux Command for Process Management

We now discuss some of the UNIX/Linux commands for process management, including ps and top. More commands will be discussed in lecture 12.

ps – Display status of processes

ps gives a snapshot of the current processes. Without options, ps prints information about processes owned by the user. Some of the commonly used options are -u, -e, and -l.

  • -e selects all processes
  • -l formats the output in the long format
  • -u displays the information in user-oriented format

The shell session in Figure 10.5 shows sample use of the ps command. The first command shows the processes running in your current session. The second command shows, page by page, the status of all the processes belonging to root. The last command shows the status of all the processes running on your system.

Use of the ps command

top – Display CPU usage of processes

top displays information about the top processes (as many as can fit on the terminal or around 20 by default) on the system and periodically updates this information. Raw CPU percentage is used to rank the processes. A sample run of the top command is shown in Figure 10.6. The output of the command also shows the current time, how long the
system has been up and running, number of processes running on the system and their status, number of CPUs in the system and their usage, amount of main memory in the system and its usage, and the size of swap space and its usage. The output also shows a lot of information about each process, including process ID, owner’s login name, priority, nice value, and size. Information about processes is updated periodically. See the manual page for the top command for more information by using the man top command.

Use of the top command