@740340735
2016-03-24T05:31:24.000000Z
字数 1951
阅读 844
操作系统
陆一洲 5140309557 of F1403020
描述一下内核在两个进程间进行上下文功换的动作。
图表 3.24 里显示的程序,说明 A 行将会输出什么?
问: 下面设计的好处和坏处分别是什么?系统层次和用户层次都要考虑到。
a. 对称和非对称通信
b. 自动和显式缓冲
c. 复制发送和引用发送
d. 固定大小和可变大小消息
// An echo server listening on port 6007.// This server reads from the client and echoes back the result.// When the client enters the character '.' ?the server closes the connection.// This conforms to RFC 862 for echo servers.import java.net.*;import java.io.*;public class EchoServer{public static final int DEFAULT_PORT = 6007;public static final int BUFFER_SIZE = 256;public static void main(String[] args) throws IOException{ServerSocket sock = null;byte[] buffer = new byte[BUFFER_SIZE];InputStream fromClient = null;OutputStream toClient = null;try {// establish the socketsock = new ServerSocket(DEFAULT_PORT);while (true){/*** now listen for connections*/Socket client = sock.accept();/*** get the input and output streams associated with the socket.*/fromClient = new BufferedInputStream(client.getInputStream());toClient = new BufferedOutputStream(client.getOutputStream());int numBytes;/** continually loop until the client closes the connection */while ( (numBytes = fromClient.read(buffer)) != -1){toClient.write(buffer,0,numBytes);toClient.flush();}fromClient.close();toClient.close();client.close();}}catch (IOException ioe) { }finally {if (sock != null)sock.close();}}}