Article Directory
- 1. Single choice
-
- 1. If a user process reads the data in a disk file through the read system call, then in the following description about this process, the correct one is ().
- 2. Among the following statements about virtual storage, the correct one is ().
- 3. Among the following options, the event that cannot happen in user mode is ().
- 4. Threads under the same process can share ()
- 5. In the process of page fault processing, the operation performed by the operating system may be ()
- 6. Among the following options, the scheduling algorithm that satisfies short task priority and does not cause starvation is ()
- 7. Among the following options, the reasonable time to lower the process priority is ()
- 8. When using locks to ensure thread safety, liveness failures may occur. Liveness failures mainly include ()
- 9. Among the following options, the operation that leads to the creation of a new process is ()
- 10. For the description of process and thread, the following is correct ()
- 2. Programming
1. Single choice
1. If a user process reads the data in a disk file through the read system call, then in the following description about this process, the correct one is ().
Ⅰ. If the data of the file is not in the memory, the process enters the sleep waiting state
II. Requesting the read system call will cause the CPU to switch from user mode to kernel modeⅢ
. The arguments to the read system call should contain the name of the file
A I, II
only B I, III
only C II, III only
D I, II, and III
Correct answer: A
should contain the file descriptor
2. Among the following statements about virtual storage, the correct one is ().
A Virtual storage can only be based on continuous allocation technology
B Virtual storage can only be based on discontinuous allocation technology
C Virtual storage capacity is only limited by external storage capacity
D Virtual storage capacity is only limited by memory capacity
Correct answer: B
1. Virtual storage is essentially the virtual address space of a process. Loading a program is to start program execution by loading part of the program into memory and leaving the rest in external memory.
2. The continuous allocation method is adopted,会使一部分内存空间处于暂时会永久的空闲状态,从而造成内存资源的浪费,并且无法从逻辑上扩大内存容量
so the realization of virtual memory can only be based on the memory management of discrete allocation.
3. The virtual memory capacity is not limited by the internal and external memory capacity, yes由CPU的寻址范围决定
.
3. Among the following options, the event that cannot happen in user mode is ().
A system call
B external interrupt
C process switch
D page fault
Correct answer: C
A system call - call matching system call function
B external interrupt - ctrl+c, interrupt program
C process switching - scheduled by the operating system kernel
D page fault - when accessing a certain memory, you can cause a page fault page phenomenon
4. Threads under the same process can share ()
A stack
B data section——code segment
C register set
D thread ID
Correct answer: B
线程共享:
Process code segment
The public data of the process (Using these shared data, threads can easily communicate with each other) The
file descriptor opened by the
process The processor of the signal
The current directory of the process and the process user ID and process group ID
线程独有:
Thread ID
stack
Error return code
Thread priority
errno
5. In the process of page fault processing, the operation performed by the operating system may be ()
Ⅰ. Modify page table Ⅱ. Disk I/O III. Allocation page frame
A I, II
only B II only
C III only
D I, II and III
correct answer: D
6. Among the following options, the scheduling algorithm that satisfies short task priority and does not cause starvation is ()
A First come, first served—beneficial to long jobs
B High response ratio priority—high priority of short processes
C Time slice rotation—fair algorithm
D Non-preemptive short task priority—low priority of long jobs, compared with short jobs Unfriendly to long jobs in many cases
Correct answer: B
7. Among the following options, the reasonable time to lower the process priority is ()
Process A's time slice is used up
Process B has just completed I/O and enters the ready queue
Process C is permanently in the ready queue
Process D changes from the ready state to the running state
Correct answer: A
8. When using locks to ensure thread safety, liveness failures may occur. Liveness failures mainly include ()
A Deadlock
B Starvation
C Livelock
D All of the above
Correct answer: D
Activity refers to the fact that a thread or process does not get CPU usage for a long time
9. Among the following options, the operation that leads to the creation of a new process is ()
I User Login Successful II Device Allocation III Start Program Execution
A Only I and II
B Only II and III
C Only I and III
DI, II and III
Correct answer: C
10. For the description of process and thread, the following is correct ()
A All threads in the parent process share the same address space, and all child processes of the parent process share the same address space
B Changing the state of the main thread in the process will affect the behavior of other threads, changing the state of the parent process will not affect other threads Child process
C Multi-threading will cause deadlock, but multi-processing will not
D The above options are not correct
Correct answer: D
1. The child process has its own independent virtual space address
2. Each thread is independently scheduled by the operating system, so it has independent state information
3. When the parent process creates a child process, the child process will copy the memory of the parent process (including lock state) may cause the child process to fall into a deadlock state
2. Programming
1. Addition without addition, subtraction, multiplication and division
Write a function to find the sum of two integers. It is required that the four arithmetic operators +, -, *, / must not be used in the function body.
Data range: Both numbers are satisfied
Advanced: Space complexity, time complexity
Example 1:
Input
1, 2
output
3
Example 2:
Input
0, 0
output
0
correct answer:
class Solution {
public:
int Add(int num1, int num2) {
while(num2 != 0)
{
int s = num1 ^ num2;
int m = (num1 & num2)<<1;
num1 = s;
num2 = m;
}
return num1;
}
};
1. The value of addition without carry: the same as the value of bitwise XOR (the same is 0, the difference is 1) 2. The
value of calculation of carry: the same as the value of bitwise AND, and then shifted one bit to the left (bitwise And: if both are 1, it is 1, and if there is 0, it is 0) (num1&num2) <<1
3. If the value of the carry is not equal to 0, continue the previous two operations
2. Triangle
Given three sides, please judge whether a triangle can be formed.
Input description:
The input contains multiple sets of data, each set of data contains three positive integers a, b, c (1≤a, b, c≤10^100).
Output description:
For each set of data, if they can form a triangle, output "Yes"; otherwise, output "No".
Example 1:
Input
1 2 3
2 2 2
Output
No
Yes
correct answer:
#include<iostream>
using namespace std;
#define add(x,y) ((x)+(y))
#define Cmp(x,y) ((x)>(y))
int main()
{
double a,b,c;
while(cin>>a>>b>>c)
{
//a+b > c && a+c > b && b+c >a
if(Cmp(add(a,b),c) && Cmp(add(a,c),b) && Cmp(add(b,c),a))
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
return 0;
}
Note: The defined type cannot use int, long, but double, otherwise the range is not enough