├── .gitignore
├── LICENSE
├── OS-master
├── CMakeLists.txt
├── CMakeLists.txt.user
├── Procress.cpp
├── Procress.h
├── app.cpp
├── app.h
├── app.ui
├── iamges.qrc
├── images.cpp
├── images.qrc
├── images
│ └── 2.png
├── main.cpp
├── os.cpp
└── os.h
├── README.en.md
├── README.md
└── pic
├── 1.png
└── mainUI.png
/.gitignore:
--------------------------------------------------------------------------------
1 | # Build and Release Folders
2 | bin-debug/
3 | bin-release/
4 | [Oo]bj/
5 | [Bb]in/
6 |
7 | # Other files and folders
8 | .settings/
9 |
10 | # Executables
11 | *.swf
12 | *.air
13 | *.ipa
14 | *.apk
15 |
16 | /.qt_for_python
17 | # Project files, i.e. `.project`, `.actionScriptProperties` and `.flexProperties`
18 | # should NOT be excluded as they contain compiler settings and other important
19 | # information for Eclipse / Flash Builder.
20 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/OS-master/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.5)
2 |
3 | project(os-master VERSION 0.1 LANGUAGES CXX)
4 |
5 | set(CMAKE_INCLUDE_CURRENT_DIR ON)
6 |
7 | set(CMAKE_AUTOUIC ON)
8 | set(CMAKE_AUTOMOC ON)
9 | set(CMAKE_AUTORCC ON)
10 |
11 | set(CMAKE_CXX_STANDARD 17)
12 | set(CMAKE_CXX_STANDARD_REQUIRED ON)
13 |
14 | find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
15 | find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
16 |
17 | set(PROJECT_SOURCES
18 | main.cpp
19 | app.h
20 | app.cpp
21 | app.ui
22 | Procress.h
23 | Procress.cpp
24 | os.h
25 | os.cpp
26 | iamges.qrc
27 | )
28 |
29 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
30 | qt_add_executable(os-master
31 | MANUAL_FINALIZATION
32 | ${PROJECT_SOURCES}
33 | )
34 | # Define target properties for Android with Qt 6 as:
35 | # set_property(TARGET os-master APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
36 | # ${CMAKE_CURRENT_SOURCE_DIR}/android)
37 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
38 | else()
39 | if(ANDROID)
40 | add_library(os-master SHARED
41 | ${PROJECT_SOURCES}
42 | )
43 | # Define properties for Android with Qt 5 after find_package() calls as:
44 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
45 | else()
46 | add_executable(os-master
47 | ${PROJECT_SOURCES}
48 | )
49 | endif()
50 | endif()
51 |
52 | target_link_libraries(os-master PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
53 |
54 | set_target_properties(os-master PROPERTIES
55 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
56 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
57 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
58 | MACOSX_BUNDLE TRUE
59 | WIN32_EXECUTABLE TRUE
60 | )
61 |
62 | if(QT_VERSION_MAJOR EQUAL 6)
63 | qt_finalize_executable(os-master)
64 | endif()
65 |
--------------------------------------------------------------------------------
/OS-master/CMakeLists.txt.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | EnvironmentId
7 | {3df73bb4-bf4e-4bd6-b449-0093f58bf1b7}
8 |
9 |
10 | ProjectExplorer.Project.ActiveTarget
11 | 0
12 |
13 |
14 | ProjectExplorer.Project.EditorSettings
15 |
16 | true
17 | false
18 | true
19 |
20 | Cpp
21 |
22 | CppGlobal
23 |
24 |
25 |
26 | QmlJS
27 |
28 | QmlJSGlobal
29 |
30 |
31 | 2
32 | UTF-8
33 | false
34 | 4
35 | false
36 | 80
37 | true
38 | true
39 | 1
40 | false
41 | true
42 | false
43 | 0
44 | true
45 | true
46 | 0
47 | 8
48 | true
49 | false
50 | 1
51 | true
52 | true
53 | true
54 | *.md, *.MD, Makefile
55 | false
56 | true
57 |
58 |
59 |
60 | ProjectExplorer.Project.PluginSettings
61 |
62 |
63 | true
64 | false
65 | true
66 | true
67 | true
68 | true
69 |
70 |
71 | 0
72 | true
73 |
74 | -fno-delayed-template-parsing
75 |
76 | true
77 | Builtin.BuildSystem
78 |
79 | true
80 | true
81 | Builtin.DefaultTidyAndClazy
82 | 8
83 |
84 | D:/Qt/QT/OS-master/CMakeLists.txt
85 |
86 |
87 |
88 | true
89 |
90 |
91 |
92 |
93 | ProjectExplorer.Project.Target.0
94 |
95 | Desktop
96 | 未命名
97 | 未命名
98 | {5facacdd-71bd-4360-bafd-a8400bd479a5}
99 | 0
100 | 0
101 | 0
102 |
103 | Debug
104 | -DCMAKE_GENERATOR:STRING=Ninja
105 | -DCMAKE_BUILD_TYPE:STRING=Debug
106 | -DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{IDE:ResourcePath}/package-manager/auto-setup.cmake
107 | -DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
108 | -DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
109 | -DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
110 | -DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
111 | D:\Qt\QT\build-os-master-unknown-Debug
112 |
113 |
114 |
115 | all
116 |
117 | true
118 | Build
119 | CMakeProjectManager.MakeStep
120 |
121 | 1
122 | Build
123 | Build
124 | ProjectExplorer.BuildSteps.Build
125 |
126 |
127 |
128 |
129 | clean
130 |
131 | true
132 | Build
133 | CMakeProjectManager.MakeStep
134 |
135 | 1
136 | Clean
137 | Clean
138 | ProjectExplorer.BuildSteps.Clean
139 |
140 | 2
141 | false
142 |
143 | false
144 |
145 | Debug
146 | CMakeProjectManager.CMakeBuildConfiguration
147 |
148 |
149 | Release
150 | -DCMAKE_GENERATOR:STRING=Ninja
151 | -DCMAKE_BUILD_TYPE:STRING=Release
152 | -DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{IDE:ResourcePath}/package-manager/auto-setup.cmake
153 | -DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
154 | -DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
155 | -DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
156 | -DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
157 | D:\Qt\QT\build-os-master-unknown-Release
158 |
159 |
160 |
161 | all
162 |
163 | true
164 | CMakeProjectManager.MakeStep
165 |
166 | 1
167 | Build
168 | Build
169 | ProjectExplorer.BuildSteps.Build
170 |
171 |
172 |
173 |
174 | clean
175 |
176 | true
177 | CMakeProjectManager.MakeStep
178 |
179 | 1
180 | Clean
181 | Clean
182 | ProjectExplorer.BuildSteps.Clean
183 |
184 | 2
185 | false
186 |
187 | false
188 |
189 | Release
190 | CMakeProjectManager.CMakeBuildConfiguration
191 |
192 |
193 | RelWithDebInfo
194 | -DCMAKE_GENERATOR:STRING=Ninja
195 | -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo
196 | -DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{IDE:ResourcePath}/package-manager/auto-setup.cmake
197 | -DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
198 | -DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
199 | -DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
200 | -DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
201 | D:\Qt\QT\build-os-master-unknown-RelWithDebInfo
202 |
203 |
204 |
205 | all
206 |
207 | true
208 | CMakeProjectManager.MakeStep
209 |
210 | 1
211 | Build
212 | Build
213 | ProjectExplorer.BuildSteps.Build
214 |
215 |
216 |
217 |
218 | clean
219 |
220 | true
221 | CMakeProjectManager.MakeStep
222 |
223 | 1
224 | Clean
225 | Clean
226 | ProjectExplorer.BuildSteps.Clean
227 |
228 | 2
229 | false
230 |
231 | false
232 |
233 | Release with Debug Information
234 | CMakeProjectManager.CMakeBuildConfiguration
235 |
236 |
237 | MinSizeRel
238 | -DCMAKE_GENERATOR:STRING=Ninja
239 | -DCMAKE_BUILD_TYPE:STRING=MinSizeRel
240 | -DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{IDE:ResourcePath}/package-manager/auto-setup.cmake
241 | -DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
242 | -DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
243 | -DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
244 | -DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
245 | D:\Qt\QT\build-os-master-unknown-MinSizeRel
246 |
247 |
248 |
249 | all
250 |
251 | true
252 | CMakeProjectManager.MakeStep
253 |
254 | 1
255 | Build
256 | Build
257 | ProjectExplorer.BuildSteps.Build
258 |
259 |
260 |
261 |
262 | clean
263 |
264 | true
265 | CMakeProjectManager.MakeStep
266 |
267 | 1
268 | Clean
269 | Clean
270 | ProjectExplorer.BuildSteps.Clean
271 |
272 | 2
273 | false
274 |
275 | false
276 |
277 | Minimum Size Release
278 | CMakeProjectManager.CMakeBuildConfiguration
279 |
280 | 4
281 |
282 |
283 | 0
284 | Deploy
285 | Deploy
286 | ProjectExplorer.BuildSteps.Deploy
287 |
288 | 1
289 |
290 | false
291 | ProjectExplorer.DefaultDeployConfiguration
292 |
293 | 1
294 |
295 | true
296 | true
297 | true
298 |
299 | 2
300 |
301 | os-master
302 | CMakeProjectManager.CMakeRunConfiguration.os-master
303 | os-master
304 | false
305 | true
306 | true
307 | false
308 | true
309 | D:/Qt/QT/build-os-master-unknown-Debug
310 |
311 | 1
312 |
313 |
314 |
315 | ProjectExplorer.Project.TargetCount
316 | 1
317 |
318 |
319 | ProjectExplorer.Project.Updater.FileVersion
320 | 22
321 |
322 |
323 | Version
324 | 22
325 |
326 |
327 |
--------------------------------------------------------------------------------
/OS-master/Procress.cpp:
--------------------------------------------------------------------------------
1 | #include "Procress.h"
2 | #include
3 |
4 | using namespace std;
5 |
6 | //构造函数
7 | Procress::Procress()
8 | {
9 | this->space = 0;
10 | this->pid = "unamed";
11 | this->state = "back";
12 | this->priority = 0;
13 | this->attribute = 0;//默认为同步进程
14 | }
15 |
16 | //构造函数重载
17 | Procress::Procress(int _space, QString _pid, int _runtime,
18 | int _priority, QString _state, int _attribute, vector pre)
19 | {
20 | this->space = _space;
21 | this->pid = _pid;
22 | this->runtime = _runtime;
23 | this->arrivaltime = 0;
24 | this->priority = _priority;
25 | this->state = _state;
26 | this->attribute = _attribute;
27 | this->preprogress = pre;
28 | }
29 |
30 | void Procress::set_Procress(int _space, QString _pid, int _runtime,int _arrivaltime,
31 | int _priority, QString _state, int _attribute)
32 | {
33 | this->space = _space;
34 | this->pid = _pid;
35 | this->runtime = _runtime;
36 | this->arrivaltime = _arrivaltime;
37 | this->priority = _priority;
38 | this->state = _state;
39 | this->attribute = _attribute;
40 | }
41 |
42 | void Procress::show_Procress()
43 | {
44 | qDebug() << "进程名称" << pid << " " << "运行时间:" << runtime << " "
45 | << "到达时间:" << arrivaltime << " "
46 | << "优先级:" << priority << " "
47 | << "状态:" << state << " "
48 | << "属性:" << attribute << " "
49 | << "所需空间:" << space << " "
50 | << "进程前驱节点:";
51 | if (preprogress.size() == 0)
52 | qDebug() << "无";
53 | for (int i = 0; i < preprogress.size(); i++)
54 | qDebug() << preprogress[i] << " ";
55 | }
56 |
57 | int Procress::get_priority()
58 | {
59 | return this->priority;
60 | }
61 |
62 | QString Procress::get_state()
63 | {
64 | return this->state;
65 | }
66 |
67 |
68 | void Procress::set_state(QString _state)
69 | {
70 | state = _state;
71 | }
72 |
73 | int Procress::get_runtime()
74 | {
75 | return runtime;
76 | }
77 |
78 | void Procress::set_runtime(int _runtime)
79 | {
80 | runtime = _runtime;
81 | }
82 |
83 | void Procress::set_priority(int _priority)
84 | {
85 | priority = _priority;
86 | }
87 |
88 | void Procress::set_arrivaltime(int _arrivaltime)
89 | {
90 | arrivaltime = _arrivaltime;
91 | }
92 |
93 | int Procress::get_arrivaltime()
94 | {
95 | return arrivaltime;
96 | }
97 |
98 | QString Procress::get_pid()
99 | {
100 | return pid;
101 | }
102 |
103 | int Procress::get_attribute()
104 | {
105 | return attribute;
106 | }
107 |
108 | int Procress::get_space()
109 | {
110 | return space;
111 | }
112 |
113 | void Procress::set_pid(QString _pid)
114 | {
115 | pid = _pid;
116 | }
117 |
118 | void Procress::set_attribute(int _attribute)
119 | {
120 | attribute = _attribute;
121 | }
122 |
123 | void Procress::set_space(int _space)
124 | {
125 | space = _space;
126 | }
127 |
128 | vector Procress::get_preprogress()
129 | {
130 | return preprogress;
131 | }
132 |
133 | void Procress::show(QStandardItemModel* model,int row)
134 | {
135 | model->setItem(row, 0, new QStandardItem(pid));
136 | model->setItem(row, 1, new QStandardItem(QString::number(runtime)));
137 | model->setItem(row, 2, new QStandardItem(QString::number(priority)));
138 | model->setItem(row, 3, new QStandardItem(QString::number(attribute)));
139 | model->setItem(row, 4, new QStandardItem(QString::number(space)));
140 | if(state == "back" || state == "ready")
141 | {
142 | //就绪队列和后备队列显示前驱节点
143 | if(preprogress.size() == 0)
144 | model->setItem(row, 5, new QStandardItem("无"));
145 | else
146 | {
147 | QString pre = "";
148 | for(int i = 0; i < preprogress.size(); i++)
149 | pre = pre + preprogress[i] + ", ";
150 | model->setItem(row, 5, new QStandardItem(pre));
151 | }
152 | model->item(row, 5)->setTextAlignment(Qt::AlignCenter);
153 | if(row % 2 == 0)
154 | model->item(row,5)->setBackground(QColor(222,234,246));
155 | }
156 | if(row % 2 == 0)
157 | {
158 | model->item(row,0)->setBackground(QColor(222,234,246));
159 | model->item(row,1)->setBackground(QColor(222,234,246));
160 | model->item(row,2)->setBackground(QColor(222,234,246));
161 | model->item(row,3)->setBackground(QColor(222,234,246));
162 | model->item(row,4)->setBackground(QColor(222,234,246));
163 | }
164 | model->item(row, 0)->setTextAlignment(Qt::AlignCenter);
165 | model->item(row, 1)->setTextAlignment(Qt::AlignCenter);
166 | model->item(row, 2)->setTextAlignment(Qt::AlignCenter);
167 | model->item(row, 3)->setTextAlignment(Qt::AlignCenter);
168 | model->item(row, 4)->setTextAlignment(Qt::AlignCenter);
169 |
170 | }
171 |
--------------------------------------------------------------------------------
/OS-master/Procress.h:
--------------------------------------------------------------------------------
1 | #ifndef PROCRESS_H
2 | #define PROCRESS_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | using namespace std;
9 |
10 | class Procress
11 | {
12 | private:
13 | QString pid; //进程名
14 | int runtime; //要求运行时间
15 | int arrivaltime; //进程到达时间,为了实现动态添加进程
16 | int priority;//进程优先级
17 | QString state;//进程状态:活动就绪、静止就绪、挂起、运行、后备
18 | int attribute;//进程属性:独立进程(0)、同步进程(1)
19 | vector preprogress;//存放同步进程的前驱进程
20 | int space;//进程所需内存空间大小
21 | public:
22 | Procress* next;//链指针
23 | Procress();//构造函数
24 | Procress(int _space, QString _pid, int _runtime,
25 | int _priority, QString _state, int _attribute, vector pre);
26 | void set_Procress(int _space, QString _pid, int _runtime, int _arrivaltime,
27 | int _priority, QString _state, int _attribute);//设置进程属性
28 | void show_Procress();//显示进程属性
29 | //void run();//进程运行
30 | void show(QStandardItemModel* model,int row);//显示该进程的信息
31 |
32 | //对外接口
33 | int get_priority();//获取进程优先级
34 | QString get_state();//获取进程状态
35 | int get_runtime();//获取运行时间
36 | int get_arrivaltime();//获取到达时间
37 | QString get_pid();//获取进程Pid
38 | int get_attribute();//获取进程属性
39 | int get_space();//获取进程所需内存空间大小
40 | vector get_preprogress();//获取进程的前驱
41 | void set_state(QString _state);//设置进程状态
42 | void set_runtime(int _runtime);//设置运行时间
43 | void set_priority(int _priority);//设置优先级
44 | void set_arrivaltime(int _arrivaltime);//设置到达时间
45 | void set_pid(QString _pid);
46 | void set_attribute(int _attribute);
47 | void set_space(int _space);
48 | };
49 |
50 |
51 |
52 |
53 | #endif // PROCRESS_H
54 |
--------------------------------------------------------------------------------
/OS-master/app.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include "app.h"
3 | #include "./ui_app.h"
4 |
5 |
6 | app::app(QWidget *parent)
7 | : QMainWindow(parent)
8 | , ui(new Ui::app)
9 | {
10 |
11 | ui->setupUi(this);
12 |
13 | painter = new QPainter(this);
14 |
15 | system = new os();
16 | QStandardItemModel* queue[6] = {};
17 | queue[0] = readyqueue;
18 | queue[1] = backqueue;
19 | queue[2] = runqueue;
20 | queue[3] = suspendqueue;
21 | queue[4] = endqueue;
22 | queue[5] = blockqueue;
23 | QTableView* Table[6] = {};
24 | Table[0] = ui->tableReady;
25 | Table[1] = ui->tableBack;
26 | Table[2] = ui->tableRun;
27 | Table[3] = ui->tablesuspend;
28 | Table[4] = ui->tableEnd;
29 | Table[5] = ui->tableblock;
30 | readyqueue = new QStandardItemModel(this);
31 | backqueue = new QStandardItemModel(this);
32 | runqueue = new QStandardItemModel(this);
33 | suspendqueue = new QStandardItemModel(this);
34 | endqueue = new QStandardItemModel(this);
35 | blockqueue = new QStandardItemModel(this);
36 | memallocationqueue = new QStandardItemModel(this);
37 | ui->tableReady->setModel(readyqueue);//创建readyqueue的table
38 | ui->tableBack->setModel(backqueue);//创建backqueue的table
39 | ui->tableRun->setModel(runqueue);//创建runqueue的table
40 | ui->tablesuspend->setModel(suspendqueue);//创建suspendqueue的table
41 | ui->tableEnd->setModel(endqueue);//创建endqueue的table
42 | ui->tableblock->setModel(blockqueue);
43 | ui->memTable->setModel(memallocationqueue);//创建内存分配情况Table
44 | memallocationqueue->setColumnCount(3);
45 | memallocationqueue->setHeaderData(0, Qt::Horizontal, "起始地址");//设置表头
46 | memallocationqueue->setHeaderData(1, Qt::Horizontal, "长度");//设置表头
47 | memallocationqueue->setHeaderData(2, Qt::Horizontal, "状态");//设置表头
48 | ui->memTable->setColumnWidth(0,70);
49 | ui->memTable->setColumnWidth(1,70);
50 | ui->memTable->setColumnWidth(2,70);
51 |
52 | blockqueue->setColumnCount(5);
53 | blockqueue->setHeaderData(0, Qt::Horizontal, "进程名");//设置表头
54 | blockqueue->setHeaderData(1, Qt::Horizontal, "运行时间");
55 | blockqueue->setHeaderData(2, Qt::Horizontal, "优先级");
56 | blockqueue->setHeaderData(3, Qt::Horizontal, "属性");
57 | blockqueue->setHeaderData(4, Qt::Horizontal, "所需空间");
58 | suspendqueue->setColumnCount(5);
59 | readyqueue->setColumnCount(6);
60 | readyqueue->setHeaderData(0, Qt::Horizontal, "进程名");//设置表头
61 | readyqueue->setHeaderData(1, Qt::Horizontal, "运行时间");
62 | readyqueue->setHeaderData(2, Qt::Horizontal, "优先级");
63 | readyqueue->setHeaderData(3, Qt::Horizontal, "属性");
64 | readyqueue->setHeaderData(4, Qt::Horizontal, "所需空间");
65 | readyqueue->setHeaderData(5, Qt::Horizontal, "前驱节点");
66 | ui->tableReady->setColumnWidth(5, 70);
67 | backqueue->setColumnCount(6);
68 | backqueue->setHeaderData(0, Qt::Horizontal, "进程名");//设置表头
69 | backqueue->setHeaderData(1, Qt::Horizontal, "运行时间");
70 | backqueue->setHeaderData(2, Qt::Horizontal, "优先级");
71 | backqueue->setHeaderData(3, Qt::Horizontal, "属性");
72 | backqueue->setHeaderData(4, Qt::Horizontal, "所需空间");
73 | backqueue->setHeaderData(5, Qt::Horizontal, "前驱节点");
74 | ui->tableBack->setColumnWidth(5, 70);
75 | runqueue->setColumnCount(5);
76 | runqueue->setHeaderData(0, Qt::Horizontal, "进程名");//设置表头
77 | runqueue->setHeaderData(1, Qt::Horizontal, "运行时间");
78 | runqueue->setHeaderData(2, Qt::Horizontal, "优先级");
79 | runqueue->setHeaderData(3, Qt::Horizontal, "属性");
80 | runqueue->setHeaderData(4, Qt::Horizontal, "所需空间");
81 | suspendqueue->setColumnCount(5);
82 | suspendqueue->setHeaderData(0, Qt::Horizontal, "进程名");//设置表头
83 | suspendqueue->setHeaderData(1, Qt::Horizontal, "运行时间");
84 | suspendqueue->setHeaderData(2, Qt::Horizontal, "优先级");
85 | suspendqueue->setHeaderData(3, Qt::Horizontal, "属性");
86 | suspendqueue->setHeaderData(4, Qt::Horizontal, "所需空间");
87 | endqueue->setColumnCount(5);
88 | endqueue->setHeaderData(0, Qt::Horizontal, "进程名");//设置表头
89 | endqueue->setHeaderData(1, Qt::Horizontal, "运行时间");
90 | endqueue->setHeaderData(2, Qt::Horizontal, "优先级");
91 | endqueue->setHeaderData(3, Qt::Horizontal, "属性");
92 | endqueue->setHeaderData(4, Qt::Horizontal, "所需空间");
93 | for(int i = 0; i < 6; i++)
94 | {
95 | Table[i]->verticalHeader()->hide();//隐藏左边一栏
96 | Table[i]->setColumnWidth(0,50);
97 | Table[i]->setColumnWidth(1,70);
98 | Table[i]->setColumnWidth(2,50);
99 |
100 | Table[i]->setColumnWidth(3,50);
101 | Table[i]->setColumnWidth(4,70);
102 | Table[i]->setEditTriggers(QAbstractItemView::NoEditTriggers);
103 | }
104 | ui->memTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
105 | ui->memTable->verticalHeader()->hide();
106 |
107 | //右键菜单实现
108 | readytableMenue = new QMenu(ui->tableReady);//就绪队列菜单
109 | suspendtableMenue = new QMenu(ui->tablesuspend);//就绪队列菜单
110 | ui->tableReady->setContextMenuPolicy(Qt::CustomContextMenu);
111 | ui->tablesuspend->setContextMenuPolicy(Qt::CustomContextMenu);
112 |
113 | //菜单栏的实现
114 | //QMenuBar
115 | connect(ui->actionSuspend, SIGNAL(triggered()), this, SLOT(Suspend()));
116 | connect(ui->actionUnsuspend, SIGNAL(triggered()), this, SLOT(Unsuspend()));
117 | connect(ui->action_setcpunum, SIGNAL(triggered()), this, SLOT(set_cpunum()));
118 | // connect(ui->actionIO, SIGNAL(triggered()), this, SLOT(IO()));
119 | // connect(ui->actionIOend, SIGNAL(triggered()), this, SLOT(IOend()));
120 |
121 | //定时器的实现
122 | timer_scheduling = new QTimer();
123 | timer_scheduling->setInterval(1000);//设置调用时间间隔为1秒
124 | timer_run = new QTimer();
125 | timer_run->setInterval(1000);//设置调用时间间隔为1s
126 | connect(timer_scheduling, SIGNAL(timeout()), this, SLOT(Scheduling()));//连接定时器
127 | connect(timer_run, SIGNAL(timeout()), this, SLOT(Run()));//连接定时器
128 | connect(ui->button_beginScheduling, SIGNAL(clicked()), this, SLOT(timestart()));//连接开始调度按钮
129 | connect(ui->button_stopScheduling, SIGNAL(clicked()), this, SLOT(timestop()));//连接暂停调度按钮
130 |
131 | //设置速度控制滑块
132 | ui->speed_control->setMaximum(2000);
133 | ui->speed_control->setMinimum(100);
134 |
135 | }
136 |
137 |
138 | app::~app()
139 | {
140 | delete ui;
141 | }
142 |
143 |
144 | void app::test()
145 | {
146 | vector v2 = { "1" };
147 | vector v3 = { "1", "2"};
148 | vector v4 = { "2", "3"};
149 | Procress* p1 = system->creatProcress(300, "1", 1, 5, 0);
150 | if (p1 == nullptr)
151 | qDebug() << "进程创建失败,前驱或进程名称错误\n";
152 | Procress* p2 = system->creatProcress(200, "2", 1, 2, 0);
153 | if (p2 == nullptr)
154 | qDebug() << "进程创建失败,前驱或进程名称错误\n";
155 | Procress* p3 = system->creatProcress(500, "3", 1, 5, 1, v3);
156 | if (p3 == nullptr)
157 | qDebug() << "进程创建失败,前驱或进程名称错误\n";
158 | Procress* p4 = system->creatProcress(600, "4", 1, 4, 1, v4);
159 | if (p4 == nullptr)
160 | qDebug() << "进程创建失败,前驱或进程名称错误\n";
161 | Procress* p5 = system->creatProcress(200, "5", 3, 1, 0);
162 | if (p5 == nullptr)
163 | qDebug() << "进程创建失败,前驱或进程名称错误\n";
164 | Procress* p6 = system->creatProcress(500, "6", 1, 8, 0);
165 | if (p6 == nullptr)
166 | qDebug() << "进程创建失败,前驱或进程名称错误\n";
167 | Procress* p7 = system->creatProcress(300, "7", 2, 1, 0);
168 | if (p7 == nullptr)
169 | qDebug() << "进程创建失败,前驱或进程名称错误\n";
170 | Procress* p8 = system->creatProcress(300, "8", 2, 1, 0);
171 | Procress* p9 = system->creatProcress(300, "9", 2, 1, 0);
172 | showinfo();
173 | //system->showtable();
174 | }
175 |
176 | void app::showinfo()
177 | {
178 | int row = 0;
179 | Procress* head[6] = {};
180 | head[0] = system->get_readyhead()->next;
181 | head[1] = system->get_backhead()->next;
182 | head[2] = system->get_runhead()->next;
183 | head[3] = system->get_suspendhead()->next;
184 | head[4] = system->get_endhead()->next;
185 | head[5] = system->get_blockhead()->next;
186 | QStandardItemModel* queue[6] = {};
187 | queue[0] = readyqueue;
188 | queue[1] = backqueue;
189 | queue[2] = runqueue;
190 | queue[3] = suspendqueue;
191 | queue[4] = endqueue;
192 | queue[5] = blockqueue;
193 | Procress* pt;
194 | for(int i = 0; i < 6; i++)
195 | {
196 | row = 0;
197 | queue[i]->removeRows(0, queue[i]->rowCount());//清空该表的所有记录
198 | pt = head[i];
199 | while(pt!=nullptr)
200 | {
201 | pt->show(queue[i], row);
202 | row++;
203 | pt = pt->next;
204 | }
205 | }
206 | vector undist = system->get_undisttable();
207 | memallocationqueue->removeRows(0, memallocationqueue->rowCount());//清除内存表中的记录
208 | for(int i = 0; i < undist.size(); i++)
209 | {
210 | memallocationqueue->setItem(i, 0, new QStandardItem(QString::number(undist[i].startadd)));
211 | memallocationqueue->setItem(i, 1, new QStandardItem(QString::number(undist[i].length)));
212 | QString _state;
213 | if(undist[i].state == "unmalloced")
214 | _state = "空闲";
215 | else
216 | _state = undist[i].state;
217 | memallocationqueue->setItem(i, 2, new QStandardItem(_state));
218 | if(_state == "空闲")
219 | {
220 | memallocationqueue->item(i,0)->setBackground(QColor(240,249,235));
221 | memallocationqueue->item(i,1)->setBackground(QColor(240,249,235));
222 | memallocationqueue->item(i,2)->setBackground(QColor(240,249,235));
223 | }
224 | else
225 | {
226 | memallocationqueue->item(i,0)->setBackground(QColor(254,245,230));
227 | memallocationqueue->item(i,1)->setBackground(QColor(254,245,230));
228 | memallocationqueue->item(i,2)->setBackground(QColor(254,245,230));
229 | }
230 | memallocationqueue->item(i, 0)->setTextAlignment(Qt::AlignCenter);
231 | memallocationqueue->item(i, 1)->setTextAlignment(Qt::AlignCenter);
232 | memallocationqueue->item(i, 2)->setTextAlignment(Qt::AlignCenter);
233 | }
234 | //更新内存使用情况
235 | vector table = system->get_undisttable();
236 | double use = 0;
237 | int mem_sum = system->get_mainmem();
238 | for(int i = 0; i < table.size(); i++)
239 | {
240 | if(table[i].state != "unmalloced")
241 | use += table[i].length;
242 | }
243 | double use_rate = use/3300 * 100;
244 |
245 | ui->progressBar_free->setValue(100-use_rate);
246 | ui->progressBar_memuse->setValue(use_rate);
247 | }
248 |
249 |
250 | void app::on_button_scheduling_clicked()
251 | {
252 | system->scheduling();
253 | showinfo();
254 | }
255 |
256 |
257 | void app::on_button_run_clicked()
258 | {
259 | system->run();
260 | showinfo();
261 | }
262 |
263 |
264 | //菜单栏中挂起槽函数实现
265 | void app::Suspend()
266 | {
267 | bool ok;
268 | QString pid = QInputDialog::getText(this, "进程挂起",
269 | "请输入需要挂起的进程pid", QLineEdit::Normal, "", &ok);
270 | if(ok)
271 | qDebug()<get_readyhead()->next;
273 | while(pt != nullptr)
274 | {
275 | if(pid == pt->get_pid())
276 | {
277 | system->suspend(pt);
278 | showinfo();
279 | return;
280 | }
281 | else
282 | pt = pt->next;
283 |
284 | }
285 | if(pt == nullptr)
286 | QMessageBox::critical(this, "输入信息非法", "该进程不存在");
287 | }
288 |
289 | void app::Unsuspend()
290 | {
291 | bool ok;
292 | QString pid = QInputDialog::getText(this, "进程解挂",
293 | "请输入需要解挂的进程pid", QLineEdit::Normal, "", &ok);
294 | if(ok)
295 | qDebug()<get_suspendhead()->next;
297 | while(pt != nullptr)
298 | {
299 | if(pid == pt->get_pid())
300 | {
301 | system->unsuspend(pt);
302 | showinfo();
303 | break;
304 | }
305 | else
306 | pt = pt->next;
307 |
308 | }
309 | if(pt == nullptr)
310 | QMessageBox::critical(this, "输入信息非法", "该进程不存在");
311 | }
312 |
313 | void app::timestart()
314 | {
315 | QMessageBox::information(this, "开始调度", "进程调度已开始");
316 | timer_scheduling->start();//开始定时
317 | QThread::msleep(500);
318 | timer_run->start();
319 | }
320 |
321 | void app::timestop()
322 | {
323 | timer_scheduling->stop();//暂停定时器
324 | timer_run->stop();
325 | QMessageBox::information(this, "暂停调度", "进程调度已暂停");
326 | }
327 |
328 | void app::Scheduling()
329 | {
330 | system->scheduling();
331 | showinfo();
332 | }
333 |
334 | void app::Run()
335 | {
336 | system->run();
337 | showinfo();
338 | }
339 |
340 | void app::on_button_addProgress_clicked()
341 | {
342 | QString pid = ui->input_pid->text();
343 | int space = ui->input_space->text().toInt();
344 | int runtime = ui->input_runtime->text().toInt();
345 | int priority = ui->input_priority->text().toInt();
346 | int attribute = ui->input_attribute->currentIndex();
347 | QString preprogress = ui->input_preprogress->text();
348 | QStringList _inputpre = preprogress.split(";");
349 | vector inputpre;
350 | for(int i = 0; i < _inputpre.size(); i++)
351 | inputpre.push_back(_inputpre[i]);
352 | //绘制下拉复选框
353 | //检查是否重名
354 | vector pidvector = system->get_pidvector();
355 | if(count(pidvector.begin(), pidvector.end(), pid))
356 | QMessageBox::critical(this, "输入信息非法", "进程pid已经存在");
357 | else if(space <= 0)
358 | QMessageBox::critical(this, "输入信息非法", "进程所需空间不得小于0");
359 | else if(runtime <= 0)
360 | QMessageBox::critical(this, "输入信息非法", "进程运行时间不得小于0");
361 | else if(priority <= 0)
362 | QMessageBox::critical(this, "输入信息非法", "进程优先级不得小于0");
363 | else if(attribute == 1)
364 | {
365 | //检查前驱节点是否合法
366 | for (int i = 0; i < inputpre.size(); i++)
367 | {
368 | if (count(pidvector.begin(), pidvector.end(), inputpre[i]))
369 | continue;
370 | else
371 | {
372 | QString a = "进程" + inputpre[i] + "不存在";
373 | QMessageBox::critical(this, "输入信息非法", a);
374 | }
375 | }
376 | system->creatProcress(space,pid,runtime,priority,attribute,inputpre);
377 | showinfo();
378 | }
379 | else
380 | if(attribute == 0)
381 | {
382 | system->creatProcress(space,pid,runtime,priority,attribute);
383 | showinfo();
384 | }
385 | }
386 |
387 |
388 |
389 | void app::on_button_randomadd_clicked()
390 | {
391 | //随机生成五个进程
392 | vector pid = system->get_pidvector();
393 | int num = 0;
394 | int i = 0;
395 | while(num < 5)
396 | {
397 | int _name = QRandomGenerator::global()->bounded(200);
398 | QString name = QString::number(_name);
399 | for(i = 0; i < pid.size(); i++)
400 | {
401 | if(name == pid[i])
402 | break;
403 | }
404 | if(i >= pid.size())
405 | {
406 | //没有重复的
407 | int space = QRandomGenerator::global()->bounded(50);
408 | space = space * 10;
409 | int priority = QRandomGenerator::global()->bounded(10);
410 | int runtime = QRandomGenerator::global()->bounded(9);
411 | runtime++;//保证runtime大于0
412 | int attribute = 0;
413 | system->creatProcress(space,name,runtime,priority,attribute);
414 | num++;
415 | }
416 | }
417 | showinfo();
418 | }
419 |
420 | void app::set_cpunum()
421 | {
422 | int num = 1;
423 | bool ok;
424 | QString _num = QInputDialog::getText(this, "设置CPU数量",
425 | "请输入CPU数量", QLineEdit::Normal, "", &ok);
426 | if(ok)
427 | qDebug()<<_num;
428 | num = _num.toInt();
429 | if(num <= 0)
430 | QMessageBox::critical(this, "输入信息非法", "CPU数量不得小于0");
431 | else
432 | system->set_cpunum(num);
433 | }
434 |
435 | //设置执行速度
436 | void app::on_speed_control_sliderMoved(int position)
437 | {
438 | timer_run->setInterval(2000-position);
439 | timer_scheduling->setInterval(2000-position);
440 | }
441 |
442 |
443 | void CalcVertexes(double startX, double startY, double endX, double endY, double& x1, double& y1, double& x2, double& y2)
444 | {
445 | /*
446 | * @brief 求得箭头两点坐标
447 | */
448 |
449 | double arrowLength = 10; // 箭头长度,一般固定
450 | double arrowDegrees = 0.5; // 箭头角度,一般固定
451 |
452 | // 求 y / x 的反正切值
453 | double angle = atan2(endY - startY, endX - startX) + 3.1415926;
454 |
455 | // 求得箭头点 1 的坐标
456 | x1 = endX + arrowLength * cos(angle - arrowDegrees);
457 | y1 = endY + arrowLength * sin(angle - arrowDegrees);
458 |
459 | // 求得箭头点 2 的坐标
460 | x2 = endX + arrowLength * cos(angle + arrowDegrees);
461 | y2 = endY + arrowLength * sin(angle + arrowDegrees);
462 | }
463 |
464 | void app::paintEvent(QPaintEvent *event)
465 | {
466 | draw_pre_after();
467 | update();
468 | }
469 |
470 | Procress* app::searchNode(QString pid)
471 | {
472 | Procress* pt = system->get_readyhead()->next;
473 | while(pt!=nullptr)
474 | {
475 | if(pt->get_pid() == pid)
476 | break;
477 | else
478 | pt = pt->next;
479 | }
480 | if(pt==nullptr)
481 | pt = system->get_runhead()->next;
482 | while(pt!=nullptr)
483 | {
484 | if(pt->get_pid() == pid)
485 | break;
486 | else
487 | pt = pt->next;
488 | }
489 | if(pt==nullptr)
490 | pt = system->get_endhead()->next;
491 | while(pt!=nullptr)
492 | {
493 | if(pt->get_pid() == pid)
494 | break;
495 | else
496 | pt = pt->next;
497 | }
498 | if(pt==nullptr)
499 | pt = system->get_backhead()->next;
500 | while(pt!=nullptr)
501 | {
502 | if(pt->get_pid() == pid)
503 | break;
504 | else
505 | pt = pt->next;
506 | }
507 | if(pt==nullptr)
508 | pt = system->get_suspendhead()->next;
509 | while(pt!=nullptr)
510 | {
511 | if(pt->get_pid() == pid)
512 | break;
513 | else
514 | pt = pt->next;
515 | }
516 | if(pt==nullptr)
517 | pt = system->get_blockhead()->next;
518 | while(pt!=nullptr)
519 | {
520 | if(pt->get_pid() == pid)
521 | return pt;
522 | else
523 | pt = pt->next;
524 | }
525 | return pt;
526 |
527 | }
528 |
529 |
530 | void app::draw_pre_after()
531 | {
532 | //先绘制节点
533 | pid = system->get_pidvector();//节点向量
534 | for(int i = 0; i < pid.size(); i++)
535 | {
536 | int row,col,x,y;
537 | row = i / 5;
538 | col = i % 5;
539 | if(row % 2 == 0)
540 | x = 1050 + 50 * col;
541 | else
542 | x = 1075 + 50 * col;
543 | if(col % 2 == 0)
544 | y = 390 + 50 * row;
545 | else
546 | y = 365 + 50 * row;
547 | Procress* pt = searchNode(pid[i]);
548 | vector preprogress = pt->get_preprogress();
549 | for(int j = 0; j < preprogress.size(); j++)
550 | {
551 | //连接节点i与其前驱j
552 | //x,y为当前节点的位置
553 | //找到前驱节点在pid中的位置
554 | int m = 0;
555 | for(m = 0; m < pid.size(); m++)
556 | if(pid[m] == preprogress[j])
557 | break;
558 | int mx,my;
559 | row = m / 5;
560 | col = m % 5;
561 | if(row % 2 == 0)
562 | mx = 1050 + 50 * col;
563 | else
564 | mx = 1075 + 50 * col;
565 | if(col % 2 == 0)
566 | my = 390 + 50 * row;
567 | else
568 | my = 365 + 50 * row;
569 | draw_line(x+5,y+3,mx+5,my+3);
570 | }
571 | draw_circle(x,y,pid[i]);
572 |
573 | }
574 | //再绘制节点直接的关系
575 | }
576 |
577 | void app::draw_circle(int x, int y, QString pid)
578 | {
579 | painter->begin(this);
580 | QPen pen;
581 | pen.setColor(QColor(47,69,84));
582 | pen.setWidth(13);
583 | painter->setPen(pen);
584 | painter->setRenderHint(QPainter::Antialiasing, true);
585 | painter->drawEllipse(x,y,13,13);
586 | pen.setColor(QColor(255,255,255));
587 | painter->setPen(pen);
588 | painter->drawText(x-3,y+8,pid);
589 | painter->end();
590 | }
591 |
592 | void app::draw_line(int lineHStartPos,int lineVStartPos,int lineHEndPos,int lineVEndPos)
593 | {
594 |
595 | painter->begin(this);
596 | QPen pen;
597 | pen.setColor(QColor(61,157,255));
598 | pen.setWidth(2);
599 | painter->setPen(pen);
600 | painter->setRenderHint(QPainter::Antialiasing, true);
601 | QLineF line(lineHStartPos, lineVStartPos, lineHEndPos, lineVEndPos);
602 | painter->drawLine(line);
603 | // 箭头的两点坐标
604 | double x1, y1, x2, y2;
605 | // 求得箭头两点坐标
606 | CalcVertexes(lineHStartPos, lineVStartPos, lineHEndPos, lineVEndPos, x1, y1, x2, y2);
607 | painter->drawLine(lineHEndPos, lineVEndPos, x1, y1); // 绘制箭头一半
608 | painter->drawLine(lineHEndPos, lineVEndPos, x2, y2); // 绘制箭头另一半
609 | painter->end();
610 | }
611 |
612 | void app::IO()
613 | {
614 | bool ok;
615 | QString pid = QInputDialog::getText(this, "进程IO",
616 | "请输入需要IO的进程pid", QLineEdit::Normal, "", &ok);
617 | if(ok)
618 | qDebug()<get_runhead()->next;
620 | while(pt != nullptr)
621 | {
622 | if(pid == pt->get_pid())
623 | {
624 | system->IO(pt);
625 | showinfo();
626 | break;
627 | }
628 | else
629 | pt = pt->next;
630 |
631 | }
632 | if(pt == nullptr)
633 | QMessageBox::critical(this, "输入信息非法", "该进程不存在");
634 | }
635 |
636 | void app::IOend()
637 | {
638 | bool ok;
639 | QString pid = QInputDialog::getText(this, "IO结束",
640 | "请输入结束IO的进程pid", QLineEdit::Normal, "", &ok);
641 | if(ok)
642 | qDebug()<get_blockhead()->next;
644 | while(pt != nullptr)
645 | {
646 | if(pid == pt->get_pid())
647 | {
648 | system->endIO(pt);
649 | showinfo();
650 | break;
651 | }
652 | else
653 | pt = pt->next;
654 |
655 | }
656 | if(pt == nullptr)
657 | QMessageBox::critical(this, "输入信息非法", "该进程不存在");
658 | }
659 |
--------------------------------------------------------------------------------
/OS-master/app.h:
--------------------------------------------------------------------------------
1 | #ifndef APP_H
2 | #define APP_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 |
20 | #include "os.h"
21 |
22 | QT_BEGIN_NAMESPACE
23 | namespace Ui { class app; }
24 | QT_END_NAMESPACE
25 |
26 | class app : public QMainWindow
27 | {
28 | Q_OBJECT
29 |
30 | public:
31 | app(QWidget *parent = nullptr);
32 | ~app();
33 | void test();
34 | void showinfo();//在tableView中显示所有的队列信息
35 |
36 | private slots:
37 | void on_button_scheduling_clicked();
38 | void on_button_run_clicked();
39 | void on_button_addProgress_clicked();//添加进程
40 | void Suspend();//菜单栏中挂起槽函数
41 | void Unsuspend();//菜单栏中的解挂槽函数
42 | void set_cpunum();//菜单栏中的设置cpunum槽函数
43 | void Scheduling();//调度槽函数
44 | void Run();//运行槽函数
45 | void timestart();//启动定时器,开始调度
46 | void timestop();//关闭定时器,暂停调度
47 | void on_button_randomadd_clicked();//随机生成5个进程
48 | void on_speed_control_sliderMoved(int position);
49 | void IO();
50 | void IOend();
51 |
52 | protected:
53 | void paintEvent(QPaintEvent *event);
54 |
55 | private:
56 | Ui::app *ui;
57 | os* system;
58 | QStandardItemModel* readyqueue;//就绪队列表格
59 | QStandardItemModel* backqueue;//后备队列表格
60 | QStandardItemModel* runqueue;//运行队列表格
61 | QStandardItemModel* suspendqueue;//挂起队列表格
62 | QStandardItemModel* endqueue;//结束队列表格
63 | QStandardItemModel* blockqueue;//阻塞队列
64 | QStandardItemModel* memallocationqueue;//内存分配情况
65 | QMenu *readytableMenue;//就绪队列菜单
66 | QMenu *suspendtableMenue;//挂起队列菜单
67 | QTimer* timer_scheduling;//定时器
68 | QTimer* timer_run;//定时器
69 | QPainter* painter;
70 | void draw_pre_after();
71 | void draw_circle(int x, int y, QString pid);
72 | void draw_line(int lineHStartPos,int lineVStartPos,int lineHEndPos,int lineVEndPos);
73 | Procress* searchNode(QString pid);
74 | vector pid;
75 | };
76 | #endif // APP_H
77 |
--------------------------------------------------------------------------------
/OS-master/app.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | app
4 |
5 |
6 |
7 | 0
8 | 0
9 | 1303
10 | 767
11 |
12 |
13 |
14 | Qt::NoContextMenu
15 |
16 |
17 | OS-master-常琪凯
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 | 70
27 | 640
28 | 110
29 | 32
30 |
31 |
32 |
33 | 调度
34 |
35 |
36 |
37 |
38 |
39 | 170
40 | 10
41 | 111
42 | 30
43 |
44 |
45 |
46 |
47 | 500
48 | 500
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 | 0
58 | 255
59 | 255
60 |
61 |
62 |
63 |
64 |
65 |
66 | 127
67 | 255
68 | 255
69 |
70 |
71 |
72 |
73 |
74 |
75 | 63
76 | 255
77 | 255
78 |
79 |
80 |
81 |
82 |
83 |
84 | 0
85 | 127
86 | 127
87 |
88 |
89 |
90 |
91 |
92 |
93 | 0
94 | 170
95 | 170
96 |
97 |
98 |
99 |
100 |
101 |
102 | 0
103 | 255
104 | 255
105 |
106 |
107 |
108 |
109 |
110 |
111 | 0
112 | 0
113 | 0
114 |
115 |
116 |
117 |
118 |
119 |
120 | 127
121 | 255
122 | 255
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 | 240
132 | 240
133 | 240
134 |
135 |
136 |
137 |
138 |
139 |
140 | 255
141 | 255
142 | 255
143 |
144 |
145 |
146 |
147 |
148 |
149 | 227
150 | 227
151 | 227
152 |
153 |
154 |
155 |
156 |
157 |
158 | 160
159 | 160
160 | 160
161 |
162 |
163 |
164 |
165 |
166 |
167 | 160
168 | 160
169 | 160
170 |
171 |
172 |
173 |
174 |
175 |
176 | 240
177 | 240
178 | 240
179 |
180 |
181 |
182 |
183 |
184 |
185 | 105
186 | 105
187 | 105
188 |
189 |
190 |
191 |
192 |
193 |
194 | 245
195 | 245
196 | 245
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 | 0
206 | 255
207 | 255
208 |
209 |
210 |
211 |
212 |
213 |
214 | 127
215 | 255
216 | 255
217 |
218 |
219 |
220 |
221 |
222 |
223 | 63
224 | 255
225 | 255
226 |
227 |
228 |
229 |
230 |
231 |
232 | 0
233 | 127
234 | 127
235 |
236 |
237 |
238 |
239 |
240 |
241 | 0
242 | 170
243 | 170
244 |
245 |
246 |
247 |
248 |
249 |
250 | 0
251 | 255
252 | 255
253 |
254 |
255 |
256 |
257 |
258 |
259 | 0
260 | 0
261 | 0
262 |
263 |
264 |
265 |
266 |
267 |
268 | 245
269 | 245
270 | 245
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 | 14
280 | true
281 |
282 |
283 |
284 | 活动就绪
285 |
286 |
287 | Qt::AutoText
288 |
289 |
290 |
291 |
292 |
293 | 520
294 | 10
295 | 111
296 | 30
297 |
298 |
299 |
300 |
301 | 14
302 | true
303 |
304 |
305 |
306 | 运行队列
307 |
308 |
309 |
310 |
311 |
312 | 190
313 | 640
314 | 110
315 | 32
316 |
317 |
318 |
319 | 运行
320 |
321 |
322 |
323 |
324 |
325 | 780
326 | 10
327 | 181
328 | 30
329 |
330 |
331 |
332 |
333 | 14
334 | true
335 |
336 |
337 |
338 | 结束队列
339 |
340 |
341 | Qt::AlignCenter
342 |
343 |
344 |
345 |
346 |
347 | 1060
348 | 10
349 | 201
350 | 30
351 |
352 |
353 |
354 |
355 | 14
356 | true
357 |
358 |
359 |
360 | 内存分配情况
361 |
362 |
363 | Qt::AlignCenter
364 |
365 |
366 |
367 |
368 |
369 | 880
370 | 330
371 | 113
372 | 27
373 |
374 |
375 |
376 |
377 |
378 |
379 | 880
380 | 370
381 | 113
382 | 27
383 |
384 |
385 |
386 |
387 |
388 |
389 | 880
390 | 410
391 | 113
392 | 27
393 |
394 |
395 |
396 |
397 |
398 |
399 | 790
400 | 330
401 | 77
402 | 22
403 |
404 |
405 |
406 | 进程名称
407 |
408 |
409 |
410 |
411 |
412 | 790
413 | 370
414 | 77
415 | 22
416 |
417 |
418 |
419 | 所需空间
420 |
421 |
422 |
423 |
424 |
425 | 790
426 | 410
427 | 77
428 | 22
429 |
430 |
431 |
432 | 运行时间
433 |
434 |
435 |
436 |
437 |
438 | 790
439 | 490
440 | 77
441 | 22
442 |
443 |
444 |
445 | 进程属性
446 |
447 |
448 |
449 |
450 |
451 | 890
452 | 490
453 | 97
454 | 28
455 |
456 |
457 | -
458 |
459 | 独立进程
460 |
461 |
462 | -
463 |
464 | 并发进程
465 |
466 |
467 |
468 |
469 |
470 |
471 | 790
472 | 530
473 | 77
474 | 22
475 |
476 |
477 |
478 | 前驱节点
479 |
480 |
481 |
482 |
483 |
484 | 850
485 | 580
486 | 104
487 | 32
488 |
489 |
490 |
491 | 添加进程
492 |
493 |
494 |
495 |
496 |
497 | 790
498 | 450
499 | 77
500 | 22
501 |
502 |
503 |
504 | 优先级:
505 |
506 |
507 |
508 |
509 |
510 | 880
511 | 450
512 | 113
513 | 27
514 |
515 |
516 |
517 |
518 |
519 |
520 | 880
521 | 530
522 | 113
523 | 27
524 |
525 |
526 |
527 |
528 |
529 | true
530 |
531 |
532 |
533 | 20
534 | 330
535 | 380
536 | 234
537 |
538 |
539 |
540 |
541 | 0
542 | 0
543 |
544 |
545 |
546 |
547 | 380
548 | 255
549 |
550 |
551 |
552 |
553 |
554 |
555 | 160
556 | 290
557 | 131
558 | 41
559 |
560 |
561 |
562 |
563 | 14
564 | true
565 |
566 |
567 |
568 | 后备队列
569 |
570 |
571 | Qt::MarkdownText
572 |
573 |
574 | Qt::AlignCenter
575 |
576 |
577 |
578 |
579 | true
580 |
581 |
582 |
583 | 20
584 | 50
585 | 380
586 | 241
587 |
588 |
589 |
590 |
591 | 380
592 | 255
593 |
594 |
595 |
596 |
597 |
598 | true
599 |
600 |
601 |
602 | 410
603 | 50
604 | 295
605 | 171
606 |
607 |
608 |
609 |
610 | 295
611 | 400
612 |
613 |
614 |
615 |
616 |
617 | true
618 |
619 |
620 |
621 | 410
622 | 260
623 | 295
624 | 131
625 |
626 |
627 |
628 |
629 | 295
630 | 400
631 |
632 |
633 |
634 |
635 |
636 |
637 | 510
638 | 225
639 | 111
640 | 31
641 |
642 |
643 |
644 |
645 | 14
646 | true
647 |
648 |
649 |
650 | 挂起队列
651 |
652 |
653 | Qt::AlignCenter
654 |
655 |
656 |
657 |
658 | true
659 |
660 |
661 |
662 | 710
663 | 50
664 | 320
665 | 239
666 |
667 |
668 |
669 |
670 | 0
671 | 0
672 |
673 |
674 |
675 |
676 | 320
677 | 520
678 |
679 |
680 |
681 |
682 |
683 |
684 | 1040
685 | 50
686 | 230
687 | 239
688 |
689 |
690 |
691 |
692 | 230
693 | 0
694 |
695 |
696 |
697 |
698 | 230
699 | 520
700 |
701 |
702 |
703 |
704 |
705 |
706 | 70
707 | 600
708 | 110
709 | 32
710 |
711 |
712 |
713 | 自动调度
714 |
715 |
716 |
717 |
718 |
719 | 190
720 | 600
721 | 110
722 | 32
723 |
724 |
725 |
726 | 暂停调度
727 |
728 |
729 |
730 |
731 |
732 | 820
733 | 295
734 | 111
735 | 31
736 |
737 |
738 |
739 |
740 | 14
741 | true
742 |
743 |
744 |
745 | 添加进程
746 |
747 |
748 | Qt::AlignCenter
749 |
750 |
751 |
752 |
753 |
754 | 610
755 | 610
756 | 124
757 | 23
758 |
759 |
760 |
761 | 90
762 |
763 |
764 |
765 |
766 |
767 | 520
768 | 610
769 | 101
770 | 22
771 |
772 |
773 |
774 | 内存使用率:
775 |
776 |
777 |
778 |
779 |
780 | 520
781 | 650
782 | 101
783 | 22
784 |
785 |
786 |
787 | 内存空闲率:
788 |
789 |
790 |
791 |
792 |
793 | 610
794 | 650
795 | 124
796 | 23
797 |
798 |
799 |
800 | 10
801 |
802 |
803 |
804 |
805 |
806 | 830
807 | 620
808 | 141
809 | 32
810 |
811 |
812 |
813 | 随机生成5个进程
814 |
815 |
816 |
817 |
818 |
819 | 330
820 | 630
821 | 160
822 | 22
823 |
824 |
825 |
826 | Qt::Horizontal
827 |
828 |
829 |
830 |
831 |
832 | 370
833 | 600
834 | 91
835 | 22
836 |
837 |
838 |
839 | 执行速度:
840 |
841 |
842 |
843 |
844 |
845 | 1080
846 | 300
847 | 141
848 | 31
849 |
850 |
851 |
852 |
853 | 14
854 | true
855 |
856 |
857 |
858 | 前驱后继图
859 |
860 |
861 | Qt::AlignCenter
862 |
863 |
864 |
865 |
866 |
867 | 510
868 | 395
869 | 111
870 | 31
871 |
872 |
873 |
874 |
875 | 14
876 | true
877 |
878 |
879 |
880 | 阻塞队列
881 |
882 |
883 | Qt::AlignCenter
884 |
885 |
886 |
887 |
888 | true
889 |
890 |
891 |
892 | 410
893 | 430
894 | 295
895 | 131
896 |
897 |
898 |
899 |
900 | 295
901 | 400
902 |
903 |
904 |
905 |
906 |
935 |
936 |
937 |
938 | 进程挂起
939 |
940 |
941 |
942 |
943 |
944 | 进程解挂
945 |
946 |
947 |
948 |
949 | 处理机数量
950 |
951 |
952 |
953 |
954 |
955 | 时间片大小
956 |
957 |
958 |
959 |
960 | 主存空间大小
961 |
962 |
963 |
964 |
965 | 进程IO
966 |
967 |
968 |
969 |
970 | IO结束
971 |
972 |
973 |
974 |
975 |
976 |
977 |
--------------------------------------------------------------------------------
/OS-master/iamges.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | images/2.png
4 |
5 |
6 |
--------------------------------------------------------------------------------
/OS-master/images.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JingMog/OS/79574d219de215747ca0ee58fa0098b1f48d87e7/OS-master/images.cpp
--------------------------------------------------------------------------------
/OS-master/images.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | images/2.png
4 |
5 |
6 |
--------------------------------------------------------------------------------
/OS-master/images/2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JingMog/OS/79574d219de215747ca0ee58fa0098b1f48d87e7/OS-master/images/2.png
--------------------------------------------------------------------------------
/OS-master/main.cpp:
--------------------------------------------------------------------------------
1 | #include "app.h"
2 |
3 | #include
4 |
5 | int main(int argc, char *argv[])
6 | {
7 | QApplication a(argc, argv);
8 | app w;
9 | w.setStyleSheet("app{border-image:url(:/images/2.png);}");
10 | w.test();
11 | w.show();
12 | return a.exec();
13 | }
14 |
--------------------------------------------------------------------------------
/OS-master/os.cpp:
--------------------------------------------------------------------------------
1 | #include "os.h"
2 |
3 |
4 | os::os()
5 | {
6 | //构造队列(链表)
7 | readyhead = new Procress;
8 | readyhead->next = nullptr;
9 | backhead = new Procress;
10 | backhead->next = nullptr;
11 | endhead = new Procress;
12 | endhead->next = nullptr;
13 | runhead = new Procress;
14 | runhead->next = nullptr;
15 | suspendhead = new Procress;
16 | suspendhead->next = nullptr;
17 | blockhead = new Procress;
18 | blockhead->next = nullptr;
19 | cpucycle = 0;
20 | mainMemory = 3000;
21 | cpunum = 2;
22 | undistributtable a = { 300, mainMemory, "unmalloced" };
23 | undistributtable b = {0, 300, "操作系统"};
24 | undisttable.push_back(b);
25 | undisttable.push_back(a);
26 | }
27 |
28 | void os::showtable()
29 | {
30 | qDebug() << "\n---------未分分区表----------" << "\n";
31 | for(int i = 0; i < undisttable.size(); i++)
32 | {
33 | qDebug() << "第" << i + 1 << "片分区\n";
34 | qDebug() << "起始地址:" << undisttable[i].startadd << "\n";
35 | qDebug() << "长度:" << undisttable[i].length << "\n";
36 | qDebug() << "状态:" << undisttable[i].state << "\n\n";
37 | }
38 | }
39 |
40 | bool os::checkpreprogress(Procress* p)
41 | {
42 | //检查进程p的所有前驱进程是否都已经完成
43 | bool ok = true;
44 | vector pre = p->get_preprogress();
45 | Procress* pt = endhead->next;
46 | for (int i = 0; i < pre.size(); i++)
47 | {
48 | pt = endhead->next;
49 | //一次检查每一个前驱
50 | while (pt != nullptr)
51 | {
52 | if (pt->get_pid() == pre[i])
53 | {
54 | break;
55 | }
56 | pt = pt->next;
57 | }
58 | //如果从while循环中退出则说明有前驱未在end队列中
59 | if (pt == nullptr)
60 | ok = false;
61 | }
62 | return ok;
63 | }
64 |
65 | void os::erasevector(int loc)
66 | {
67 | //删除指定loc位置的vector元素
68 | int i = 0;
69 | for (vector::iterator iter = undisttable.begin(); iter != undisttable.end(); iter++, i++)
70 | {
71 | if (i == loc)
72 | {
73 | undisttable.erase(iter);
74 | break;
75 | }
76 | }
77 | }
78 |
79 | //首次适应算法分配主存空间
80 | bool os::mallocmem(Procress* p)
81 | {
82 | //cout << "正在为" << p->get_pid() << "进程分配主存空间" << endl;
83 | //cout << "所需空间" << p->get_space() << endl;
84 | //针对分区状态表
85 | bool isok = false;
86 | int space = p->get_space();
87 | for (int i = 0; i < undisttable.size(); i++)
88 | {
89 | if (undisttable[i].length > space && undisttable[i].state == "unmalloced")
90 | {
91 | //如果第i块未分分区大小大于进程所需空间并且该空间未分配
92 | //则修改其起始地址,修改空间大小
93 | //并新建一条记录插入表中
94 | undistributtable prs = { undisttable[i].startadd, space, p->get_pid() };
95 | undisttable.insert(undisttable.begin() + i, prs);//指定位置插入元素
96 | undisttable[i+1].length = undisttable[i+1].length - space;
97 | undisttable[i+1].startadd = undisttable[i+1].startadd + space;
98 | return true;
99 | }
100 | if (undisttable[i].length == space && undisttable[i].state == "unmalloced")
101 | {
102 | //如果第i块未分分区等于进程所需空间
103 | //则直接修改第i块空间的状态
104 | undisttable[i].state = p->get_pid();
105 | return true;
106 | }
107 | }
108 | //如果遍历完所有的未分分区表之后还不能
109 | return false;
110 | }
111 |
112 | //回收主存空间
113 | void os::reclaimmem(Procress* p)
114 | {
115 | /*
116 | 进程完成之后回收主存空间,并与相邻空闲分区合并
117 | 3中情况:
118 | 1.上下分区均不空闲,则该进程所占空间加入到未分分区表中(按起始地址加入
119 | 2.上方分区空闲,则修改上方未分分区记录
120 | 3.下方分区空闲,则修改下方未分分区记录
121 | 4.上下分区均空闲,则修改上方分区记录,删除下方分区记录
122 | */
123 | int size = undisttable.size();
124 | QString pid = p->get_pid();
125 | //该进程是分区表中第一个记录
126 | if (size == 1)
127 | {
128 | undisttable[0].state = "unmalloced";
129 | return;
130 | }
131 | if (undisttable[0].state == pid)
132 | {
133 | if (undisttable[1].state == "unmalloced")
134 | {
135 | //如果该进程在分区表中第一条记录中并且下一个记录未分配,则合并并且删除第一个
136 | undisttable[0].length += undisttable.at(1).length;//长度相加
137 | undisttable[0].state = "unmalloced";
138 | erasevector(1);//删除第二个分区
139 | return;
140 | }
141 | else
142 | {
143 | //该进程在分区表中第一条并且下一条已分配
144 | undisttable[0].state = "unmalloced";
145 | return;
146 | }
147 | }
148 | //该进程是分区表中最后一个进程
149 | if (undisttable.at(size-1).state == pid)
150 | {
151 | if (undisttable[size - 2].state == "unmalloced")
152 | {
153 | //最后一个进程且前一个分区未分配,则合并
154 | undisttable[size - 2].length += undisttable[size - 1].length;
155 | undisttable[size - 2].state = "unmalloced";
156 | erasevector(size - 1);
157 | return;
158 | }
159 | else
160 | {
161 | //最后一条且上一条已分配
162 | undisttable[size - 1].state = "unmalloced";
163 | return;
164 | }
165 | }
166 | for (int i = 1; i < size-1; i++)
167 | {
168 | //遍历分区状态表查找分区记录
169 | if (undisttable[i].state == pid)
170 | {
171 | if (undisttable.at(i - 1).state == "unmalloced" && undisttable.at(i + 1).state == "unmalloced")
172 | {
173 | //上下分区均空闲
174 | undisttable[i - 1].length += undisttable[i].length + undisttable[i + 1].length;
175 | erasevector(i);
176 | erasevector(i);
177 | return;
178 | }
179 | else if (undisttable.at(i - 1).state == "unmalloced" && undisttable.at(i + 1).state != "unmalloced")
180 | {
181 | //只有上方分区空闲
182 | undisttable[i - 1].length += undisttable[i].length;
183 | erasevector(i);
184 | return;
185 | }
186 | else if (undisttable.at(i - 1).state != "unmalloced" && undisttable.at(i + 1).state == "unmalloced")
187 | {
188 | //只有下方分区空闲
189 | undisttable[i].length += undisttable[i+1].length;
190 | undisttable[i].state = "unmalloced";
191 | erasevector(i+1);
192 | return;
193 | }
194 | else
195 | {
196 | //均不空闲
197 | undisttable[i].state = "unmalloced";
198 | return;
199 | }
200 | }
201 | }
202 | }
203 |
204 | void os::Sort(Procress* head)
205 | {
206 | Procress* pre, * p, * tail, * temp;
207 | tail = NULL;
208 | if (head->next == nullptr)
209 | return;
210 | while ((head->next) != tail)//(head->next)!=tail同样适用 ,多执行最后一个步比较
211 | {
212 | p = head->next;
213 | pre = head;
214 | while (p->next != tail)
215 | {
216 | if ((p->get_priority()) < (p->next->get_priority()))
217 | {
218 | pre->next = p->next; //交换节点方法二
219 | temp = p->next->next;
220 | p->next->next = p;
221 | p->next = temp;
222 | p = pre->next; //p回退一个节点
223 | }
224 | p = p->next; //p再前进一个节点
225 | pre = pre->next;
226 | }
227 | tail = p;
228 | }
229 | }
230 |
231 | //进程调度
232 | //从就绪队列中挑选优先级最高的进程进入运行队列
233 | void os::scheduling()
234 | {
235 | //此时ready链表第一个节点即为最高优先级的节点
236 | Procress* pt = readyhead->next;
237 | Procress* prept = readyhead;
238 | //如果pt不为空
239 | //获取运行队列的长度
240 | pt = runhead->next;
241 | for (int i = 0; i < cpunum; i++)
242 | {
243 | pt = readyhead->next;
244 | prept = readyhead;
245 | while (pt != nullptr)
246 | {
247 | //如果该进程的前驱已执行,则可对其进行调度,否则调度ready队列中的其他进程
248 | if(checkpreprogress(pt) == false)
249 | {
250 | //前驱未完成
251 | pt->set_state("block");
252 | prept->next = pt->next;
253 | addProcress(pt);
254 | break;
255 | }
256 | // else
257 | // qDebug()<get_pid()<<"完成";
258 | pt->set_state("run");
259 | prept->next = pt->next;
260 | addProcress(pt);
261 | break;
262 |
263 | prept = prept->next;
264 | pt = pt->next;
265 | }
266 | }
267 |
268 | }
269 |
270 | void os::backscheduling()
271 | {
272 | //从后备队列中调度优先级最高的作业
273 | //后备队列首进程分配主存
274 | Procress* pt = backhead->next;
275 | Procress* pre = backhead;
276 | if (pt == nullptr)
277 | return;
278 | while(pt != nullptr)
279 | {
280 | if (mallocmem(pt) == true)
281 | {
282 |
283 | //主存空间分配成功,将其从back队列中移除并加入到ready队列中
284 | pre->next = pt->next;
285 | pt->set_state("ready");
286 | addProcress(pt);
287 | return;
288 |
289 | }
290 | pre = pre->next;
291 | pt = pt->next;
292 | }
293 |
294 | }
295 |
296 | void os::run()
297 | {
298 | cpucycle++;//cpu执行周期加一
299 | //将run队列中的进程运行时间减1,优先权减1
300 | Procress* pt = runhead->next;
301 | Procress* prept = runhead;
302 | int _runtime, _priority;
303 | while (pt != nullptr)
304 | {
305 | _runtime = pt->get_runtime();
306 | _runtime--;
307 | pt->set_runtime(_runtime);
308 | _priority = pt->get_priority();
309 | if(_priority>0)
310 | _priority--;
311 | pt->set_priority(_priority);
312 | //如果要求运行时间为0,则将其移入结束链表,并回收主存空间
313 | if (_runtime == 0)
314 | {
315 | reclaimmem(pt);//回收主存空间
316 | pt->set_state("end");
317 | //将其移出run队列
318 | prept->next = pt->next;
319 | addProcress(pt);
320 | }
321 | else
322 | {
323 | //一个时间片结束后重新排序,进行下轮调度
324 | pt->set_state("ready");
325 | prept->next = pt->next;
326 | addProcress(pt);
327 | }
328 | pt = prept->next;
329 | }
330 | return_to_ready();
331 | }
332 |
333 | void os::return_to_ready()
334 | {
335 | //判断阻塞队列中的进程其前驱是否完成
336 | Procress* pt = blockhead->next;
337 | Procress* prept = blockhead;
338 | while(pt != nullptr)
339 | {
340 | //如果阻塞队列中的某个进程前驱全部完成,则将其加到就绪队列中
341 | if(checkpreprogress(pt))
342 | {
343 | return__(pt);
344 | prept = prept->next;
345 | pt = pt->next;
346 | return;
347 |
348 | }
349 | else
350 | {
351 | qDebug()<get_pid();
352 | prept = pt->next;
353 | pt = pt->next;
354 | qDebug()<<"继续遍历";
355 | }
356 |
357 | }
358 | }
359 |
360 | void os::return__(Procress* p)
361 | {
362 | Procress* pt = blockhead;
363 | while (pt->next != nullptr)
364 | {
365 | if (pt->next->get_pid() == p->get_pid())
366 | {
367 | //从挂起队列中删除
368 | pt->next = p->next;
369 | break;
370 | }
371 | else
372 | pt = pt->next;
373 | }
374 | p->set_state("ready");
375 | addProcress(p);
376 |
377 | }
378 |
379 | //判断当前进程状态并将其加入对应链表中
380 | void os::addProcress(Procress* p)
381 | {
382 | //QString _pid = p->get_pid();
383 | Procress* pt;
384 | QString _state = p->get_state();
385 | if (_state == "ready")
386 | {
387 | pt = readyhead->next;
388 | readyhead->next = p;
389 | p->next = pt;
390 | }
391 | else if (_state == "run")
392 | {
393 | pt = runhead->next;
394 | runhead->next = p;
395 | p->next = pt;
396 | }
397 | else if (_state == "back")
398 | {
399 | pt = backhead->next;
400 | backhead->next = p;
401 | p->next = pt;
402 | }
403 | else if (_state == "suspend")
404 | {
405 | pt = suspendhead->next;
406 | suspendhead->next = p;
407 | p->next = pt;
408 | }
409 | else if (_state == "block")
410 | {
411 | pt = blockhead->next;
412 | blockhead->next = p;
413 | p->next = pt;
414 | }
415 | else
416 | {
417 | //end
418 | pt = endhead->next;
419 | endhead->next = p;
420 | p->next = pt;
421 | }
422 | Sort(readyhead);
423 | Sort(backhead);
424 | backscheduling();
425 | }
426 |
427 | Procress* os::creatProcress(int _space, QString _pid, int _runtime,
428 | int _priority, int _attribute, vector pre)
429 | {
430 | //检查前驱节点合法性
431 | for (int i = 0; i < pre.size(); i++)
432 | {
433 | if (count(pidvector.begin(), pidvector.end(), pre[i]))
434 | continue;
435 | else
436 | {
437 | qDebug() << "进程" << pre[i] << "不存在" << "\n";
438 | return nullptr;
439 | }
440 | }
441 | //检查pid名称合法性
442 | if (count(pidvector.begin(), pidvector.end(), _pid))
443 | {
444 | qDebug() << "进程名:" << _pid << "已经存在,请检查" << "\n";
445 | return nullptr;
446 | }
447 | pidvector.push_back(_pid);
448 | QString _state = "back";
449 | Procress* p = new Procress(_space, _pid, _runtime, _priority, _state, _attribute, pre);
450 | p->set_arrivaltime(cpucycle);
451 | addProcress(p);
452 | return p;
453 | }
454 |
455 | //挂起进程
456 | void os::suspend(Procress* p)
457 | {
458 | //对就绪队列中的进程可以挂起
459 | //先遍历ready队列找到该进程的前驱
460 | Procress* prept = readyhead;
461 | while (prept->next != nullptr)
462 | {
463 | if (prept->next->get_pid() == p->get_pid())
464 | {
465 | //找到p的前驱节点prept
466 | qDebug() <<"找到需要挂起的节点";
467 | break;
468 | }
469 |
470 | else
471 | prept = prept->next;
472 | }
473 | if(prept != nullptr)
474 | prept->next = p->next;
475 | p->set_state("suspend");
476 | qDebug()<<"从ready中删除了改节点";
477 | reclaimmem(p);
478 | addProcress(p);
479 | }
480 |
481 | //解挂
482 | void os::unsuspend(Procress* p)
483 | {
484 | //从挂起队列中解挂某一个进程
485 | //如果分配内存成功,则将其加到ready队列中,否则将其加到back中
486 | //先遍历挂起队列找到节点的前驱
487 | Procress* pt = suspendhead;
488 | while (pt->next != nullptr)
489 | {
490 | if (pt->next->get_pid() == p->get_pid())
491 | {
492 | //从挂起队列中删除
493 | pt->next = p->next;
494 | break;
495 | }
496 | else
497 | pt = pt->next;
498 | }
499 | if (mallocmem(p))
500 | {
501 | p->set_state("ready");
502 | }
503 | else
504 | p->set_state("back");
505 | addProcress(p);
506 | }
507 |
508 | void os::set_cpunum(int num)
509 | {
510 | cpunum = num;
511 | }
512 |
513 | void os::set_mainMemery(int num)
514 | {
515 | mainMemory = num;
516 | }
517 |
518 | Procress* os::get_readyhead()
519 | {
520 | return readyhead;
521 | }
522 |
523 | Procress* os::get_backhead()
524 | {
525 | return backhead;
526 | }
527 |
528 | Procress* os::get_endhead()
529 | {
530 | return endhead;
531 | }
532 |
533 | Procress* os::get_runhead()
534 | {
535 | return runhead;
536 | }
537 |
538 | Procress* os::get_suspendhead()
539 | {
540 | return suspendhead;
541 | }
542 |
543 | Procress* os::get_blockhead()
544 | {
545 | return blockhead;
546 | }
547 |
548 | vector os::get_undisttable()
549 | {
550 | return undisttable;
551 | }
552 |
553 | vector os::get_pidvector()
554 | {
555 | return pidvector;
556 | }
557 |
558 | int os::get_mainmem()
559 | {
560 | return mainMemory;
561 | }
562 |
563 | void os::IO(Procress* p)
564 | {
565 | //对就绪队列中的进程可以挂起
566 | //先遍历ready队列找到该进程的前驱
567 | Procress* prept = runhead;
568 | while (prept->next != nullptr)
569 | {
570 | if (prept->next->get_pid() == p->get_pid())
571 | {
572 | break;
573 | }
574 |
575 | else
576 | prept = prept->next;
577 | }
578 | if(prept != nullptr)
579 | prept->next = p->next;
580 | p->set_state("block");
581 | addProcress(p);
582 | }
583 |
584 | void os::endIO(Procress* p)
585 | {
586 | //对就绪队列中的进程可以挂起
587 | //先遍历ready队列找到该进程的前驱
588 | Procress* prept = blockhead;
589 | while (prept->next != nullptr)
590 | {
591 | if (prept->next->get_pid() == p->get_pid())
592 | {
593 | break;
594 | }
595 |
596 | else
597 | prept = prept->next;
598 | }
599 | if(prept != nullptr)
600 | prept->next = p->next;
601 | p->set_state("ready");
602 | addProcress(p);
603 | }
604 |
--------------------------------------------------------------------------------
/OS-master/os.h:
--------------------------------------------------------------------------------
1 | #ifndef OS_H
2 | #define OS_H
3 | #include
4 | #include
5 |
6 | #include
7 | #include
8 | #include "Procress.h"
9 | using namespace std;
10 |
11 | //分区状态表
12 | struct undistributtable
13 | {
14 | int startadd;//起始地址
15 | int length;//长度
16 | QString state;//分区状态,若占用,则写该进程的pid;若空闲,则写unmalloced
17 | };
18 |
19 |
20 | class os
21 | {
22 | private:
23 | Procress* readyhead;//就绪队列
24 | Procress* backhead;//后备队列
25 | Procress* endhead;//结束队列
26 | Procress* runhead;//运行队列
27 | Procress* suspendhead;//挂起队列
28 | Procress* blockhead;
29 | int mainMemory;//主存空间大小
30 | int cpucycle;//当前CPU执行周期,用来记录进程到达时间
31 | int cpunum;//cpu核心数
32 | vector undisttable;//分区状态表
33 | vector pidvector;//pid向量组
34 |
35 | void Sort(Procress* pBegin);
36 | void erasevector(int loc);//删除未分分区表中指定位置的元素
37 | void reclaimmem(Procress* p);//回收内存
38 | bool mallocmem(Procress* p);//分配内存
39 |
40 | void addProcress(Procress* p); //增加进程到就绪队列中
41 | bool checkpreprogress(Procress* p);//检查进程的所有前驱节点是否已经全部执行完成
42 | void return_to_ready();
43 | void return__(Procress* p);
44 | public:
45 | os();//构造函数
46 | //void show();
47 | void showtable();
48 | void scheduling();//调度进程
49 | void backscheduling();//从后备队列中调度一作业进入内存
50 | void suspend(Procress* p);//挂起进程
51 | void unsuspend(Procress* p);//解挂
52 | void run(); //运行
53 | Procress * creatProcress(int _space, QString _pid, int _runtime,
54 | int _priority, int _attribute, vector pre = vector());//创建进程
55 |
56 | //void showtableinfo(Ui::app * ui);//在表格中显示信息
57 |
58 | void set_cpunum(int num);
59 | void set_mainMemery(int num);
60 | Procress* get_readyhead();
61 | Procress* get_backhead();
62 | Procress* get_endhead();
63 | Procress* get_runhead();
64 | Procress* get_suspendhead();
65 | Procress* get_blockhead();
66 | vector get_undisttable();
67 | vector get_pidvector();
68 | int get_mainmem();//获取主存空间
69 |
70 | void IO(Procress* p);
71 | void endIO(Procress* p);
72 | };
73 |
74 |
75 |
76 | #endif // OS_H
77 |
--------------------------------------------------------------------------------
/README.en.md:
--------------------------------------------------------------------------------
1 | # OS-master
2 |
3 | #### Description
4 | 操作系统课程设计,实现进程调度,模拟内存分配。C++实现
5 |
6 | #### Software Architecture
7 | Software architecture description
8 |
9 | #### Installation
10 |
11 | 1. xxxx
12 | 2. xxxx
13 | 3. xxxx
14 |
15 | #### Instructions
16 |
17 | 1. xxxx
18 | 2. xxxx
19 | 3. xxxx
20 |
21 | #### Contribution
22 |
23 | 1. Fork the repository
24 | 2. Create Feat_xxx branch
25 | 3. Commit your code
26 | 4. Create Pull Request
27 |
28 |
29 | #### Gitee Feature
30 |
31 | 1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
32 | 2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
33 | 3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
34 | 4. The most valuable open source project [GVP](https://gitee.com/gvp)
35 | 5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
36 | 6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
37 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # OS-master
2 |
3 |
4 | #### 实验目的
5 | 多道系统中,进程与进程之间存在同步与互斥关系。当就绪进程数大于处理机数时,需要按照某种策略决定哪些进程先占用处理机。在可变分区管理方式下,采用首次适应算法实现主存空间的分配和回收。
6 | 模拟实现处理机调度及内存分配及回收机制,以对处理机调度的工作原理以及内存管理的工作过程进行更深入的了解。
7 |
8 |
9 | #### 实验具体内容
10 | - 设计一个抢占式优先权调度算法实现多处理机调度的程序,并且实现在可变分区管理方式下,采用首次适应算法实现主存空间的分配和回收。
11 | - PCB 内容包括:进程名/PID;要求运行时间(单位时间);优先权;状态;进程属性:独立进程、同步进程(前趋、后继)。
12 | - 可以随机输入若干进程,可随时添加进程,并按优先权排序;
13 | - 从就绪队首选进程运行:优先权-1;要求运行时间-1;要求运行时间为 0 时,撤销该进程;一个时间片结束后重新排序,进行下轮调度;
14 | - 自行假设主存空间大小,预设操作系统所占大小并构造未分分区表。表目内容:起址、长度、状态(未分/空表目)。对内存空间分配采用首次适应算法。
15 | - 进程完成后,回收主存,并与相邻空闲分区合并。
16 | - 设置后备队列和挂起状态。若内存空间足够,可自动从后备队列调度一作业进入。被挂起进程入挂起队列,设置解挂功能用于将制定挂起进程解挂入就绪队列。
17 | - 最好采用图形界面。
18 |
19 | ## 需求分析
20 | ### 进程的设计
21 | 为了实现进程调度,首先要设计进程的类型。本次实验采用基于对象的高级语言C++,因此进程在该问题中可设计为Procress类,该类仅包括一些基本的数据结构,可以使外界访问私有变量的接口和信息展示这些最基本的功能。
22 |
23 | 将Procress的属性和方法封装起来之后在后续可以方便地使用。
24 |
25 | 进程的私有变量包括进程名(即进程Pid),要求运行时间,进程到达时间,进程优先级,进程状态(后备、活动就绪、阻塞、挂起、结束),进程属性(独立进程与同步进程),进程的前驱节点(仅针对同步进程)和进程所需的空间大小。
26 |
27 | 类包含的方法为仅有展示该类的信息和外界访问类私有变量的接口。
28 | ### 调度算法的实现
29 | 操作系统中最重要的就是CPU资源的管理,要想管理好CPU资源就要合理地调度进程。本次实验采用抢占式优先权调度完成。
30 |
31 | 由于模拟的是多处理机系统,因此每一时刻处在运行态的进程有多个,需要设置运行队列来展示处于运行状态的进程。要想实现优先权调度就要在进程的属性中增加优先权,同时在就绪队列中对进程按优先权排序,如果就绪队列中的进程数量足够,每次调度可以从就绪队列中挑选前n个进程,将其状态设置为“run”,并从原队列中删除,加到运行队列中。
32 |
33 | 为了实现抢占式调度,需要等到每次时间片结束之后重新对进程进行调度,而非等到进程全部运行完成。每次运行完一个时间片,进程的优先级将减一并重新回到就绪队列,对就绪队列中的进程重新按照优先权排序并重新调度,此时如果有优先级更高的进程进入则可实现抢占式调度。
34 |
35 | 若每次运行之后进程要求运行的时间减为0,则说明进程结束,将其状态设置为“end”,移入到结束队列中。
36 | ### 内存的分配与回收
37 | 内存的分配与回收采用的是可变分区管理方式,采用首次适应算法来实现主存空间的分配与回收。
38 |
39 | 要实现可变分区管理,首先要设置分区状态表。分区状态表为向量,向量中每个元素为分区记录数组,包括起始地址,长度,分区状态。如果分区未分配,则设置分区状态为“unmalloced”,否则设置为对应进程的pid。
40 |
41 | 首先在构造函数中为分区状态表添加第一块分区,即初始化内存空间。起始地址为0,长度为主存空间大小,状态为“unmalloced”。之后只需要对进程操作时调用分配和回收函数即可。
42 |
43 | 主存空间的分配采用首次适应算法。遍历分区状态表,如果当前分区(i)长度大于进程(p)所需长度,则修改i的状态为p的pid,i的长度为p所需空间。若剩余空间为0,则直接退出,否则增加一条记录到分区状态表中,起始地址为i的起始地址+p的空间,长度为i的长度减p的空间,同时设置状态为“unmalloced”。若遍历结束仍未找到长度大于p所需空间的分区,则返回False。
44 |
45 | 主存空间回收首先遍历分区状态表,找到分区状态等于进程pid的分区,然后设置其状态为空闲。之后需要根据不同情况对分区状态表进行不同的合并操作。如果当前分区为第一块分区,需要判断下一块分区状态是否空闲,若空闲则合并;如果当前分区为最后一块分区,需要判断上一块分区是否空闲,若空闲则合并;若既不是第一块分区又不是最后一块分区,则需要判断上下两块分区的状态是否空闲,从而执行相应的合并操作。
46 |
47 | ### 进程挂起
48 | 进程挂起时需要回收进程的内存空间,然后设置进程状态为“suspend”,之后将其从就绪队列中移除,然后加入到挂起队列中。
49 |
50 | 进程解挂时首先为其分配主存空间,如果分配成功,则将其状态设置为“ready”并且从原队列移除,移入就绪队列。若主存空间分配失败,则将其状态设置为“back”并且从原队列移除,移入后备队列。
51 |
52 | ### 阻塞队列
53 | 进程分为独立进程和同步进程,独立进程没有前驱,同步进程设置前驱进程。同步进程需要等到其全部前驱全部运行完成它才可以运行。为此,需要设置阻塞态,当某一进程被调度时首先检查其前驱节点是否完成,如果前驱节点全在结束队列中,则直接进入运行态,否则进入阻塞态,直到该进程所有前驱进程全部完成,它才可以再次被调度。
54 |
55 | 与挂起状态不同的是,阻塞队列中的进程仍然在内存空间中,它的状态转移不需要进行内存空间的分配与回收。
56 |
57 | ### 后备队列
58 | 当某一时刻进程数过多,主存空间无法容纳所有的进程,此时需要将多余的进程暂时放到后备队列中,后备队列中的进程不占用主存空间。一旦主存空间足够,将会自动从后备队列中调度进程,为其分配主存空间并将其加入就绪队列。
59 |
60 | 为此,需要在每次调度之前遍历就绪队列,检查为其分配主存空间是否成功,如果成功则将其加入就绪队列,否则继续向后遍历。
61 |
62 | ### 程序流程图
63 |
64 | 
65 |
66 | ### 主界面展示
67 | 
68 |
69 |
--------------------------------------------------------------------------------
/pic/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JingMog/OS/79574d219de215747ca0ee58fa0098b1f48d87e7/pic/1.png
--------------------------------------------------------------------------------
/pic/mainUI.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JingMog/OS/79574d219de215747ca0ee58fa0098b1f48d87e7/pic/mainUI.png
--------------------------------------------------------------------------------