FIT2100 Assign 02 2018 IPC (final revised)

FIT2100 Assignment #2 Interprocess Communication
with C Programming Week 10 Semester 2 2018
Mr Daniel Kos
Admin Tutor, Faculty of IT. Email: © 2016-2018, Monash University
September 14, 2018
© 2016-2018, Faculty of IT, Monash University

Revision Status
$Id: FIT2100-Assignment-02.tex, Version 1.0 2017/10/02 12:50 Jojo $
$Id: FIT2100-Assignment-02.tex, Version 2.0 2018/09/05 13:03 Daniel $
$Id: FIT2100-Assignment-02.tex, Version 2.1 2018/09/06 21:36 Daniel $
$Id: FIT2100-Assignment-02.tex, Version 2.2 2018/09/09 15:11 Daniel $
$Id: FIT2100-Assignment-02.tex, Version 2.3 2018/09/11 13:52 Jojo $
$Id: FIT2100-Assignment-02.tex, Version 2.4 2018/09/14 13:00 Daniel $
© 2016-2018, Faculty of IT, Monash University

CS Help, Email: tutorcs@163.com
CONTENTS 3
1 Introduction 5
2 Background 6 2.1 Whatisadisplayserver?……………………….. 6 2.2 InterprocessCommunication……………………… 6 2.3 HowtoaccesstheVirtualTerminalsinLinux……………… 7
3 Display Server 9
3.1 Task1:MicrosoftWindow? ……………………… 9 3.1.1 Requirements ………………………… 9 3.1.2 Running your server as a stand-alone desktop environment . . . . . . . 10
3.2 Task2:Addasinglequitbutton …………………… 11 3.2.1 Note…………………………….. 11
3.3 Task3:Multipleclientsatatime…………………… 12 3.3.1 Limitationsofyourdesktopenvironment . . . . . . . . . . . . . . . . 12
3.4 ImportantNotes …………………………… 14
3.5 MarkingCriteria …………………………… 14
4 Submission 15 4.1 Deliverables …………………………….. 15 4.2 AcademicIntegrity:PlagiarismandCollusion ……………… 15
5 Appendix A: bash script for standalone running 17
© 2016-2018, Faculty of IT, Monash University

CONTENTS 4
6 Appendix B: Waiting for multiple input sources with select() 18
© 2016-2018, Faculty of IT, Monash University

1 Introduction 5
1 Introduction
This second programming assignment is due on 7th October 2018 (Sunday) by 5:00pm. It is worth 15% of the total unit marks. A penalty of 5% per day will apply for late submission. Refer to the FIT2100 Unit Guide for the policy on extension or special consideration.
Note that this is an individual assignment and must be your own work. Please pay attention to Section 4.2 of this document on the University’s policies on the Academic Integrity, Plagiarism and Collusion.
This assignment consists of three implementation tasks. Each task should be implemented separately as individual C programs. All the program les and any supporting documents should be compressed into one single le for submission. (The submission details are given in Section 4.)
Assessment: Each of the three tasks has an equal weightage of marks.
© 2016-2018, Faculty of IT, Monash University

2 Background 6
2 Background
2.1 What is a display server?
A big part of an operating system’s job is sharing of resources among processes.
Consider your computer’s display. Most laptops only have one screen, so operating environ- ments like Windows provide a utility to allow multiple processes to share the display at the same time. This utility is known as a display server.
One program (the `server’) has exclusive access to the computer’s display. Although it may appear that you have multiple process windows sharing your screen at once, this is actually one process handling the display of all information on behalf of the other applications.
Other programs (`clients’ such as Calculator, Notepad, Firefox, etc.) connect to the display server via inter-process communication and send any information to be displayed on the screen. If multiple clients are running at once, the display server will display each client application in a dierent `window’ area of the screen.1
Your assignment is to build your own simple display server, displaying information from multiple clients on one screen, based on sockets as you have explored in the Interprocess Communication practical. Task 1 is a simple display server supporting only a single client application, building up to multiple clients in Task 3.
2.2 Interprocess Communication
Interprocess communication is a Unix facility to enable two or more distinct processes to communicate with each other within the same computer system as well as across a network system.
As presented in Practical 5 (Week 9), there are a number of mechanisms that can be deployed to support interprocess communication as a client-server model. Under the setting of this model, one process is referred to as the server whose responsibility is to fulll or satisfy the requests put forward to it by other processes, referred to as clients. In this assignment, we will focus on sockets.
Prior to the development of operating environments like Windows 1.0 and Macintosh System 1 during the 1980s, only one application could use the screen at a time. In modern versions of Windows, the display server is known as GDI+ and in modern versions of macOS, the display server component is known as Apple Quartz. In many Linux environments, the display server is known simply as X.
© 2016-2018, Faculty of IT, Monash University

2.3 How to access the Virtual Terminals in Linux 7
The server process must already be running prior to starting a client process, or the client will have nothing to connect to. It can be helpful to run the server and client(s) inside dierent terminal windows.
2.3 How to access the Virtual Terminals in Linux
While using the regular Linux desktop environment in your VM, you have only been using one of the virtual terminals (VTs) that Linux provides.
You can switch to another virtual terminal to run commands if your desktop environment crashes, or you can run two dierent desktop environments at the same time.
Use your VirtualBox host key (this is often the RightCtrl key on your keyboard, but can be changed in your VirtualBox settings), together with the Function keys (F1 to F8) at the top of your keyboard, to switch between your virtual terminals. See Table 1 and the notes below  your system may be dierent.
Table 1: Default key combinations for switching between dierent VTs in your VM environ- ment.
RightCtrl+F1 RightCtrl+F2 RightCtrl+F3 RightCtrl+F4 RightCtrl+F5 RightCtrl+F6 RightCtrl+F7 RightCtrl+F8
for… You should see…
VT1 Startup messages (if any), or a login prompt
VT2 TTY login prompt for starting a text-only session here VT3 TTY login prompt for starting a text-only session here VT4 TTY login prompt for starting a text-only session here VT5 TTY login prompt for starting a text-only session here VT6 TTY login prompt for starting a text-only session here VT7 *** Your regular desktop environment ***
VT8 Empty terminal for running a second desktop environment
– On some laptop computers, you will need to hold down the [Fn] key as well, in order to access the F1-F8 keys on your keyboard.
– On a MacBook or other Apple device, the required key combination is Command+Fn+… instead of the key mentioned above.
– If you have changed your VirtualBox host key, use the key you have selected instead of the key mentioned above.
– In some cases, you might need to allow VirtualBox to `capture’ your keyboard.
– If you use Linux natively (without a VM), use Ctrl+Alt instead of RightCtrl, but note that your particular Linux distribution may manage the VTs in a dierent way.
© 2016-2018, Faculty of IT, Monash University

2.3 How to access the Virtual Terminals in Linux 8
In this assignment, we will be creating a (very) simple desktop environment, which will run in the 8th `VT slot’ (VT 8), but you will control it by running commands in your regular desktop environment (VT 7).
Please play around with switching between the VTs (try logging in to the text-only VTs for an old-school Unix experience), and switching back to your regular desktop environment until you get comfortable with this feature.
© 2016-2018, Faculty of IT, Monash University

3 Display Server 9
3 Display Server
3.1 Task 1: Microsoft Window?
In this task, you will implement a display server that only accepts a connection from a single client process.
To create our display server, we need to begin with a socket server program. We will also need a client application to test our server with. The server program should create a new socket and name it with a Unix domain name (pathname), such that the client program will know which socket to connect to for communication. The server will then listen to the incoming connection request from the client program.
The client program, on the other hand, should attempt to connect to the known socket setup by the server program. Once successfully connected, the client should allow the user to type input into the TTY terminal, and send the user’s terminal input to the server through that socket, to be displayed on the screen by the server.
You may adapt your socketserver.c and socketclient.c code from Practical #5 for this.
Note: For Task 1, please name your main server source le as task1server123456789.c, and the source le for the client program as client123456789.c, where 123456789 is your student ID number. (The same client program will be used for all three tasks of this assign- ment.)
3.1.1 Requirements
You should modify your completed socket client and server code from the practical in order to satisfy the following requirements:
1. The socket le should be created as /tmp/a2-123456789.socket where 123456789 is your student ID.2 You should also modify your client to connect to the socket at this location.
2. When the client connects to the server, it should rst send its name to the server followed by a newline. After this, it should take all the user’s input entered into the terminal and send this to the server process.
The /tmp/ directory is a useful place to store temporary les, since it is automatically cleaned out each time the system is rebooted.
© 2016-2018, Faculty of IT, Monash University

程序代写 CS代考 加QQ: 749389476
Task 1: Microsoft Window? 10
Modify the server program to use ioL so that instead of printing plain TTY output, it prints characters received from the client into a element which should rst be printed into the ioL console. The box should be created when the client’s connection is accepted, and the rst line of characters received (i.e. the name of the client) should be used to decorate the box with the program title. Your server program should be run using the iol command. An example is shown in Figure 1.
Figure 1: Sample server output when the user runs a client named socketclient (which connects to the server) and the user enters text into the client process. The `window’ was created using a box with width=100,{%} in order to ll the screen horizontally. Note: you do not need to display the output in exactly this way as long as you visually dierentiate between the title and the window contents in some way. Also note that you are not required to print each line of client input on a separate line on the server. In Task 3, we will allow the user to create multiple windows.
3.1.2 Running your server as a stand-alone desktop environment
There is a bash script provided in Appendix A near the end of this assignment paper. This script will run your display server in the 8th virtual terminal slot (VT 8), as explained earlier in the background information.
You should modify the script to use the command needed to run your socket server program, and try running your display server as a separate desktop environment. You will need to switch back to VT 7 (your regular desktop) in order to run your client and enter input into your client. (Pressing Ctrl+C in the TTY window you ran the script from should be able to terminate your desktop environment for now. You will implement a better solution for this in Task 2.)
© 2016-2018, Faculty of IT, Monash University

3.2 Task 2: Add a single quit button 11
You should try running your desktop environment in this way for each of the tasks in order to see what a real user’s experience of your desktop environment would be like.
3.2 Task 2: Add a single quit button
It would be good to provide a way for the user to shut down their desktop environment once they are done.
In this task, you are required to extend your display server from Task 1 by adding a single button to the screen for the user to click when they wish to shut down your display server.
Note: For your improved Task 2 server, please name your main server source le as task2server123456789.c where 123456789 is your student ID number.
You can use the following code to create the button, or implement it in your own way:
printf(“