Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Practical #2

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions 01.report.shell.commands.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
root@Admin:~# echo hello word
hello word
root@Admin:~# passwd
New password:
Retype new password:
passwd: password updated successfully
root@Admin:~# date
Tue 14 Jan 2020 05:16:05 AM EST
root@Admin:~# hostname
Admin
root@Admin:~# arch
x86_64
root@Admin:~# uname -a
Linux Admin 5.3.0-kali3-amd64 #1 SMP Debian 5.3.15-1kali1 (2019-12-09) x86_64 GNU/Linux
root@Admin:~# dmesg
[37621.154873] [drm] ring test on 3 succeeded in 4 usecs
[37621.154881] [drm] ring test on 4 succeeded in 4 usecs
[37621.330603] [drm] ring test on 5 succeeded in 2 usecs
[37621.330608] [drm] UVD initialized successfully.
[37621.330669] [drm] ib test on ring 0 succeeded in 0 usecs
[37621.330732] [drm] ib test on ring 1 succeeded in 0 usecs
[37621.330780] [drm] ib test on ring 2 succeeded in 0 usecs
[37621.330814] [drm] ib test on ring 3 succeeded in 0 usecs
[37621.330846] [drm] ib test on ring 4 succeeded in 0 usecs
[37622.009224] [drm] ib test on ring 5 succeeded
root@Admin:~/Desktop# uptime
05:19:26 up 11:41, 1 user, load average: 0.62, 0.57, 0.57
root@Admin:~/Desktop# who am i
root@Admin:~/Desktop# whoami
root
root@Admin:~/Desktop# who
root tty7 2020-01-13 17:39 (:0)
root@Admin:~/Desktop# id
uid=0(root) gid=0(root) groups=0(root)
root@Admin:~/Desktop# last
root tty7 :0 Mon Jan 13 17:39 still logged in

wtmp begins Fri Dec 20 13:57:13 2019
root@Admin:~/Desktop# finger
Login Name Tty Idle Login Time Office Office Phone
root root tty7 11:41 Jan 13 17:39 (:0)
root@Admin:~/Desktop# w
05:20:03 up 11:41, 1 user, load average: 0.72, 0.59, 0.58
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root tty7 :0 17:39 11:41m 47:27 47:27 /usr/lib/xorg/Xorg :0 -seat seat0 -au

18 changes: 18 additions & 0 deletions 02.report.pipe.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
root@Admin:~# ls | grep list
root@Admin:~# wc -l /etc/passwd
54 /etc/passwd
root@Admin:~# free
total used free shared buff/cache available
Mem: 8136024 2028432 4716216 348744 1391376 5454432
Swap: 8300540 12272 8288268

root@Admin:~# cat /proc/cpuinfo | grep core
core id : 0
cpu cores : 2
core id : 1
cpu cores : 2

root@Admin:~/Downloads# find *.jpg | wc -l
8


16 changes: 16 additions & 0 deletions 03.process.shell.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
root@Admin:~# ps -A
PID TTY TIME CMD
1 ? 00:00:02 systemd
2 ? 00:00:00 kthreadd
3 ? 00:00:00 rcu_gp
4 ? 00:00:00 rcu_par_gp
6 ? 00:00:00 kworker/0:0H-kblockd
9 ? 00:00:00 mm_percpu_wq
10 ? 00:00:00 ksoftirqd/0
root@Admin:~# wireshark
root@Admin:~# ps -A | grep wireshark
18981 pts/1 00:00:00 wireshark
root@Admin:~# kill -STOP 18981
root@Admin:~# kill -CONT 18981
root@Admin:~# kill -KILL 18981

35 changes: 35 additions & 0 deletions 04.practical.work.fork.exec.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

int main(int argc, char const *argv[]) {
printf("Main before fork()\n");
int pid = fork();

if (pid == 0){
int pid2 = fork();

if (pid2 == 0){
printf("I am child after fork(), launching ps -ef\n");
char *args[] = {"/bin/ps", "-ef", NULL};
execvp("/bin/ps", args);
}
else {
wait(NULL);
printf("I am parent after fork(), child is %d\n", pid2);
}

printf("I am child after fork(), launching free -h\n");
char *args[] = {"free", "-h", NULL};
execvp("free", args);
}
else {
wait(NULL);
printf("I am parent after fork(), child is %d\n", pid);
}
printf("Complete!\n");
return 0;

}
14 changes: 14 additions & 0 deletions 05.report.proccess.scheduler.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/proc/sched_debug

vdhieu@Admin:~$ cat /proc/sched_debug | grep -e systemd | awk '{print $5}'
120
2746650
1014
1642
35074

/proc/<processID>/sched

vdhieu@Admin:~$ cat /proc/1/sched | grep nr_switches
nr_switches : 2762212

6 changes: 6 additions & 0 deletions 07.report.thread.info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
vdhieu@Admin:~$ ps -o nlwp 59481
58

vdhieu@Admin:~$ ls /proc/59481/task | wc -w
56

44 changes: 44 additions & 0 deletions 08.report.works.pthread.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

#include <stdio.h>
#include <math.h>
#include <pthread.h>

void *primeCalc()
{
int n = 0;
for (int i = 2; i < 1000000; i++)
{
int isPrime = 1;
for (int j = 2; j < sqrt(i); j++)
if (i % j == 0)
{
isPrime = 0;
break;
}
if (isPrime == 1) printf("Prime number %d: %d\n",n++,i);
}
}
void *fiboCalc()
{
printf("Fibo number 1:1\n");
printf("Fibo number 2:1\n");
int first = 2, sec = 3, n = 3;
while (first < 1000000 && sec < 1000000)
{
printf("Fibo number %d:%d\n", n++,first);
printf("Fibo number %d:%d\n", n++,sec);
first += sec;
sec += first;
}

}

int main()
{
pthread_t prime_t, fibo_t;
pthread_create(&prime_t, NULL, primeCalc, NULL);
pthread_create(&fibo_t, NULL, fiboCalc, NULL);
pthread_join(prime_t, NULL);
pthread_join(fibo_t, NULL);
return 0;
}
80 changes: 80 additions & 0 deletions 09.report.scheduling.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
Skip to content
Search or jump to…

Pull requests
Issues
Marketplace
Explore

@hieuvdbi9102
Learn Git and GitHub without any code!
Using the Hello World guide, you’ll start a branch, write comments, and open a pull request.


Sylbanie
/
os2020
forked from SonTG/os2020
0
076
Code
Pull requests 0 Actions
Projects 0
Wiki
Security 0
Insights
os2020/09.report.scheduling.txt
@gdxpub gdxpub Add parts of answer for exercise 9
f11cc67 on Mar 31
50 lines (42 sloc) 3.06 KB

+-------------------------------------------+
| |
p1 | 8ms |
| |
+-------------------------------------------+

+---------------------+
| |
p2 | 4ms |
| |
+---------------------+

+------+
| |
p3 | 1ms |
| |
+------+

+--------------------------+
| |
p4 | 5ms |
| |
+--------------------------+

+-------------------------------------------+---------------------+------+--------------------------+
| | | | |
FCFS | 8ms | 4ms | 1ms | 5ms | 0, 8-0.4, 12-1, 13-1.3 ms
| | | | |
+-------------------------------------------+---------------------+------+--------------------------+

+-------------------------------------------+------+---------------------+--------------------------+
| | | 1ms) | |
SJF | 8ms | 1ms | 4ms | 5ms | 0, 9-0.4, 8-1, 13-1.3ms
| | | | |
+-------------------------------------------+------+---------------------+--------------------------+

+--+---+------+--------------------+---------------------------+-------------------------------------+
| | | | | | |
SRTF |p1|p2 | p3 | p2 | p4 | p1 | (0.6+1+3.4+5), (0+1), 0, (5.4-1.3)ms
| | | | | | |
+--+---+------+--------------------+---------------------------+-------------------------------------+
0.4 0.6 1ms 3.4ms 5ms 7.6ms

+--+---+--+------+------+------+----+------+------+------+------+------+------+--+
| | | | | | | | | | | | | | |
RR |p1|p2 |p3| p4 | p1 | p2 |p3 | p1 | p2 | p4 | p1 | p2 | p4 |p2|
| | | | | | | | | | | | | | |
+--+---+--+------+------+------+----+------+------+------+------+------+------+--+
.4 .6 .3 1ms 1 1 .7 1 1 1 1 1 1 .4

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ Students are expected to:
Student Info
=========================

* Student Name: *Put your name here*
* Student ID: *Put your ID here*
* Student Name: Vũ Đức Hiếu
* Student ID: BI9-102