1 Further study on process switching
Timer Interrupt is a non-cooperative approach to enforce process scheduling. To achieve this, the operating system relies on a hardware timer to generate periodic interrupts, which trigger process switching.
When the timer interrupt occurs, the currently running process is halted, and control is transferred to the OS (kernel). And the scheduler determines whether the current process should continue or if another process should run. If a new process is selected, the OS saves the context (registers, program counter, stack pointer) of the current process and loads the context of the next process.
2 Basic concepts of terminal and shell
image
I use tmux to seperate the terminal.
2. The process is managed by the OS, not the terminal itself. Therefore, we can kill any process run on the OS in different terminal.
Maxlight changed 2 months agoView mode Like Bookmark
由於近日在 Mac 上執行 SDL2 的時候遇到一些問題,發現這問題是在 Mac 上才會有的,到 Linux 上反而就沒事了,因此我打算直接使用 Docker ,並且藉由 X11 把畫面投影在 Mac 上。
以下是我踩過很多坑之後得到的作法!
Create a Docker container
$ docker run ubuntu:18.04
$ docker ps -a
你可以藉由第一個指令創建一個 ubuntu 18.04 的 container ,並且用第二個指令看到他的 container ID 。
Enter Docker terminal
$ docker start {container ID}
Maxlight changed a year agoView mode Like Bookmark
Problem
PA CSES 1629 Movie Festival
https://vjudge.net/problem/CSES-1629
Solution
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define N 200005
#define int long long
using namespace std;
Maxlight changed a year agoView mode Like Bookmark
:::warning
這個題目我在做測試的時候主要在UBUNTU的環境,用mac的人要注意一下,mac沒有gdb,但有lldb(我不會用。
至於sanitizer的部分,在clang3.1之後應該都有。
:::
這題的重點在於是否懂 Little Endian ,如果懂就結束了。
如果你不知道什麼是 Little Endian 就真的該打屁股了,上課都不認真,去二刷一遍 L紀的課再回來寫這題,我知道你懶得去找哪一部影片,看我多貼心連結我都給你了,趕快去二刷一下(或者有人可能是第一次看?)。
Alice code
一開始我們來看看 Alice 的程式
Maxlight changed a year agoView mode Like 2 Bookmark
在這一題makefile可以看看助教給的<a href="https://hackmd.io/@cp2023/cp1-hw3-info#34-Tower-of-Hanoi">關係圖</a>,接著看看助教在作業給的最後一句,You need to implement two different functions in another C code and prepare a header file.,根據助教給的資料,以及TA hour助教說的東西,我自己的理解是這樣的,助教要我們提供三個.c檔,一個是主程式,也就是我們要call function的hw0304.c檔,一個是用迴圈實現的函式,一個是遞迴實現的函式,此外要我們寫一個header file,且該header file裡面會僅放一個函式的宣告,藉由將不同的程式揉在一起,來實踐不同的方式,我想這樣講可能有聽沒有懂,我來用我的資料實際示範一次。
首先我們會有三個檔案,分別是hw0304.c, hw0304-1.c, hw0304-2.c, hw0304.h,各個檔案的內容大概會長的像這樣(以下只是範例,但基本上大同小異)。
<strong>hw0304.c</strong>
#include <stdio.h>
#include <stdint.h>
#include "hw0304.h"
int main(){
printf("Please enter the disk number (2-20): ");
int32_t n;
Maxlight changed a year agoView mode Like Bookmark
學完物件導向程式設計後可以來了解重載運算子重載,operator overloading也可以叫做運算子覆載,或運算子多載,反正意思差不多,這裡就稱為重載運算子重載,至於為何要使用運算子重載呢?先來看一個例子:
int main(void){
int a = 4, b = 6, c;
c = a + b;
std::cout << c; //output:10
}
這個例子中可以很清楚的看到我用一個「加號」將a和b相加,這當然沒問題,那下面這個例子呢?
#include <iostream>
Maxlight changed 2 years agoView mode Like Bookmark