Best代写-最专业靠谱代写IT | CS | 留学生作业 | 编程代写Java | Python |C/C++ | PHP | Matlab | Assignment Project Homework代写

C语言操作系统代写 | CSc 360 Programming Assignment 1 P1: A Process Manager (PMan)

C语言操作系统代写 | CSc 360 Programming Assignment 1 P1: A Process Manager (PMan)

本次加拿大代写是C语言操作系统的一个Programming Assignment

1 Goals

This assignment is designed to help you:

1. get familiar with C programming,
2. get familiar with system calls related to process management,
3. get familiar with the process control block (PCB).

You are required to implement your solution in C (other languages are not allowed). Your work
will be tested on

Note: is a particular machine at the UVic Department of Computer Sci-
ence. It does not mean “any Linux machine” at UVic. Even more importantly, it does not mean any
“Unix-like” machine, such as a Mac OS X machine—many students have developed their programs
for their Mac OS X laptops only to find that their code works differently on
resulting in a substantial loss of marks.

You can remote access by ssh SSH clients
are available for a wide variety of operating systems including Linux, Mac OS and Windows.
Be sure to study the man pages for the various systems calls and functions suggested in this
assignment. The system calls are in Section 2 of the man pages, so you should type (for example):

$ man 2 waitpid

2 Schedule

In order to help you finish this programming assignment on time, the schedule of this assignment
has been synchronized with both the lectures and the tutorials. There are three tutorials arranged
during the course of this assignment.

3 Requirements

3.1 Prompt for user input

Your PMan needs to show the prompt for user input. For example, when you run PMan by type in$ ./PMan

It prompts
PMan: >
for user input.

3.2 Background Execution of Programs

PMan allows a program to be started in the background—that is, the program is running, but PMan
continues to accept input from the user. You will implement a simplified version of background
execution that supports executing processes in the background.

If the user types: bg foo, your PMan will start the program foo in the background. That is,
the program foo will execute and PMan will also continue to execute and give the prompt to accept
more commands.

The command bglist will have PMan display a list of all the programs currently executing in
the background, e.g.,:

123: /home/user/a1/foo
456: /home/user/a1/foo
Total background jobs: 2

In this case, there are 2 background jobs, both running the program foo, the first one with
process ID 123 and the second one with 456.
Your PMan needs to support the following commands:

1. The command bgkill pid will send the TERM signal to the job with process ID pid to terminate
that job.

2. The command bgstop pid will send the STOP signal to the job pid to stop (temporarily) that

3. The command bgstart pid will send the CONT signal to the job pid to re-start that job (which
has been previously stopped).

See the man page for the kill() system call for details.

Your PMan must indicate to the user when background jobs have terminated. Read the man
page for the waitpid() system call. You are suggested to use the WNOHANG option.

3.3 Status of Process

Your PMan needs to support a command pstat pid to list the following information related to
process pid, where pid is the Process ID.

1. comm : The filename of the executable, in parentheses. This is visible whether or not the
executable is swapped out.

2. state : One of the following characters, indicating process state: R (Running), S (Sleeping
in an interruptible wait), D (Waiting in uninterruptible disk sleep), Z (Zombie), T (Stopped
(on a signal) or (before Linux 2.6.33) trace stopped ), t (Tracing stop (Linux 2.6.33 onward)),
W (Paging (only before Linux 2.6.0)), X (Dead (from Linux 2.6.0 onward)), x (Dead (Linux
2.6.33 to 3.13 only)), K (Wakekill (Linux 2.6.33 to 3.13 only)), W (Waking (Linux 2.6.33 to
3.13 only)), P (Parked (Linux 3.9 to 3.13 only)).

3. utime: Amount of time that this process has been scheduled in user mode, measured in clock
ticks (divide by sysconf( SC CLK TCK)). This includes guest time, guest time (time spent
running a virtual CPU, see below), so that applications that are not aware of the guest time
field do not lose that time from their calculations.

4. stime: Amount of time that this process has been scheduled in kernel mode, measured in
clock ticks (divide by sysconf( SC CLK TCK)).

5. rss: Resident Set Size: number of pages the process has in real memory. This is just the pages
which count toward text, data, or stack space. This does not include pages which have not
been demand-loaded in, or which are swapped out.

6. voluntary ctxt switches: Number of voluntary context switches (since Linux 2.6.23).

7. nonvoluntary ctxt switches: Number of involuntary context switches (since Linux 2.6.23).

If process pid does not exist, PMan returns an error like:

Error: Process 1245 does not exist.

In the above example, 1245 is the pid value.

To summarize, your PMan should support the following commands: bg, bglist, bgkill,
bgstop, bgstart, and pstat. If the user types an unrecognized command, an error message is
given by PMan, e.g.,

PMan:> ttest
PMan:> ttest: command not found