-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c94b28
commit 6726047
Showing
8 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,6 @@ node_modules | |
yarn-error.log | ||
.history | ||
.vscode | ||
.DS_Store | ||
.DS_Store | ||
|
||
nohup.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Operating Systems: Three Easy Pieces | ||
|
||
[网址](https://pages.cs.wisc.edu/~remzi/OSTEP/) | ||
|
||
[代码地址](https://github.com/remzi-arpacidusseau/ostep-code) | ||
|
||
## 使用docker | ||
|
||
```shell | ||
docker run -it --rm --entrypoint /bin/sh -v $(pwd):/code bluewaitor/linuxc | ||
``` | ||
|
||
## Intro | ||
|
||
```shell | ||
gcc -o cpu cpu.c -Wall | ||
./cpu A | ||
|
||
./cpu A & ./cpu B & ./cpu C & ./cpu D & # 后台运行 | ||
|
||
# 结束方法 | ||
# ps 查看进程 | ||
kill -9 PID | ||
|
||
# fg 将进程放到前台 | ||
# ctrl + c 结束进程 | ||
|
||
# 关掉整个terminal | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef __COMMON_H__ | ||
#define __COMMON_H__ | ||
|
||
#include <sys/time.h> | ||
#include <assert.h> | ||
|
||
double GetTime() { | ||
struct timeval t; | ||
int rc = gettimeofday(&t, NULL); | ||
assert(rc == 0); | ||
return (double) t.tv_sec + (double) t.tv_usec / 1e6; | ||
} | ||
|
||
void Spin(int howlong) { | ||
double t = GetTime(); | ||
while (GetTime() - t < (double) howlong) | ||
; // do nothing in loop | ||
} | ||
|
||
|
||
#endif |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include "common.h" | ||
|
||
int main(int argc, char* argv[]) { | ||
setbuf(stdout, NULL); // 使用nohup的时候,需要设置这个,否则会出现输出不到文件的情况 | ||
|
||
if (argc != 2) { | ||
fprintf(stderr, "Usage: %s <string>\n", argv[0]); | ||
exit(1); | ||
} | ||
for (int i = 0; i < argc; i ++) { | ||
printf("argv[%d] = %s\n", i, argv[i]); | ||
} | ||
|
||
char *str = argv[1]; | ||
|
||
while (1) | ||
{ | ||
Spin(1); | ||
printf("%s\n", str); | ||
} | ||
|
||
return 0; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <assert.h> | ||
#include <unistd.h> | ||
#include "common.h" | ||
|
||
int main(int argc, char *argv[]) { | ||
int *p = malloc(sizeof(int)); | ||
assert(p != NULL); | ||
printf("(%d) address pointed to by p: %p\n", getpid(), p); | ||
*p = 0; | ||
while (1) | ||
{ | ||
Spin(1); | ||
*p = *p + 1; | ||
printf("(%d) p: %d\n", getpid(), *p); | ||
} | ||
return 0; | ||
} |