Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
Operating Systems 2230
Computer Science & Software Engineering
Labsheet 5
This labsheet requires you to examine the process creation and execution facilities supported by the
Windows-XP operating system and the Java programming language.
1. Examine the sample (extended) solution of Labsheet 4 Question 3, in the file
/cslinux/examples/CITS2230/Lab4/runit.c.
Repeat this question under the Windows-XP operating system, using the Microsoft Visual-Studio
environment to develop the C program. The Windows program should be of a similar length, but
will probably require you to do more reading to understand the parameters to the process creation
functions.
Start by reading about CreateProcess(), GetStartupInfo(), and WaitForSingleObject().
2. The Java programming language also supports the creation of new processes, using its classes
java.lang.Runtime and java.lang.Process. Implement something similar to runit in Java. Cor-
rectly handle the exceptions associated with not being able to create a new process and not being
able to wait for its termination.
Oops! Where did the output of the new process go? How can we see it?
3. Using whatever facilities you feel are most appropriate, measure the time taken to spawn and execute
your processes under both Linux and Windows-XP (C programs), and within the Java programming
language environment.
Is this a fair comparison?
1
4. Each computer running Linux in Lab 2.1 (only) has a large 100MB file in its temporary directory,
named /tmp/bigfile. (If the machine you’re using does not have this file, reboot the machine and it
will be created.)
Under Linux, write a short C program to read the contents of this large file. The contents of the file
are not important (it’s just multiple copies of the Hugs distribution in the same file), we just want
to read the file, and ignore its contents. Notice that we are reading this large file from the local hard
disk, not across a network connection.
Read the online Linux documentation about the system calls open(), read(), and close() (Section 2
in each case). The function call open("/tmp/bigfile", O_RDONLY) is sufficient to open the file for
reading.
Read the contents of the file into a C character array. Do not attempt to have one 100MB array(!),
instead keep reading from the file in “small pieces”.
Run your program many times, reading different amounts of data each time, until you reach the
end-of-file. Use read sizes of say 10 bytes, 100 bytes, 1 KB, and 10KB, into a sufficiently large array.
Measure the execution time and transfer rate of your program using the timing routines that you
developed in Question 3 of Labsheet 2, or /cslinux/examples/CITS2230/Lab2/q2-3.c.
5. Copy the (same) large file from /cslinux/examples/CITS2230/bigfile to the local Windows-XP tem-
porary directory. Now use Windows-XP to repeat the previous question. Read the online Windows-
XP documentation about the system calls CreateFile(), ReadFile(), and CloseHandle(). The call
CreateFile("c:\tmp\bigfile",GENERIC_READ,0,0,OPEN_EXISTING,0,0) is sufficient to open the
file for reading, and the call
ReadFile(fileHandle, char_buffer, reqd_size, &received, 0) is sufficient to read the file.
2