T
Biên
www.hutech.edu.vn
*1.2018.COS318*
:
I
.................................................................................................................. I
.......................................................................................................... IV
BÀI 1:
........................................................................ 1
.................................................................................... 1
........................................................................................ 2
......................................................... 4
................................................................................................ 4
.......................................................................................6
.................................................................................... 6
TRÌNH ................................................................................... 7
1.4.
.............................................................................. 7
........................................................................................ 7
........................................................................................ 7
........................................................................................ 8
1.4.
....................................................................................... 8
................................................................................................ 9
................................................................................................................. 10
............................................................................. 14
..................................................................................................... 14
................................................................................ 14
........................................................................................ 14
...................................................................................... 15
2.
........................................................................... 16
................................................................................................................. 20
..................................................................... 24
............................................................. 24
.......................................................................................... 27
..................................................................... 27
............................................................................... 30
................................................................................................ 30
........................................................................... 31
..................................................................................... 34
..................................................................................................... 34
system ................................................................ 34
exec ................................................ 35
fork ................................................................... 36
....................................................................... 37
II
................................................................................................................. 38
.................................................................. 44
5.1 KHÁI QUÁT ...................................................................................................... 44
............................................................................................... 44
................................................................................................... 44
.............................................................................. 45
................................................................................... 45
.................................................................................................... 46
................................................................................................... 46
............................................................................................ 46
..................................................................................... 47
5.
................................................................................... 47
................................................................................................................. 49
......................................................................................... 59
KET .................................................................................... 59
6.1.1 Socket ........................................................................................................ 59
.............................................................................................. 59
6.2 CÁCH SOCKET LÀM
6.2.
.................................................................................. 64
................................................................................... 64
.................................................................................................. 66
....................................................................................... 67
....................................................................................... 68
6.2.
................................................................................ 69
.............................................................................. 69
............................................................................................ 69
............................................................................................... 70
ÌNH KHÁCH.................................... 73
....................................................................................................... 78
.......................................................................................................... 78
............................................................. 78
.................................................................................... 78
....................................................................................... 79
........................................................................................................... 79
7.2.1 Bài 1 .......................................................................................................... 79
7.2.2 Bài 2 .......................................................................................................... 81
7.2.3 Bài 3 .......................................................................................................... 82
............................................................................................ 86
X ................................................ 86
8.1.1 Mutex là gì .................................................................................................. 86
................................................................................ 86
8.1.3 Khóa và tháo khóa cho mutex ........................................................................ 87
III
.................................................................................................. 88
............................................................................... 88
I SEMAPHORE .................................................................. 92
8.2.1 Semaphore là gì ? ........................................................................................ 92
.............................................................................. 92
.......................................................................... 95
............................................................................................. 98
..................................................................................................... 98
........................................................................... 98
........................................................................................... 98
-job-first SJF) ................................... 101
.............................................. 105
....................................................................................... 109
10.1
G UNIX VÀ LINUX ................................................... 109
.................................................................................. 109
...................................................................... 109
.............................................................................. 111
............................................................................ 114
.............................................................................. 115
IV
Máy Tính.
tin
cùng tên
Bài 4
Trình b
,
.
Bài 5: GIAO
Trình bày các
.
V
Bài 6:
Trình bày
Bài 7:
.
Bài 8:
Bài 9:
Trình bày cá
Sinh v
,
VI
-
-
50%.
50%.
BÀI 1:
QUAN
1
BÀI 1: T
1.1 CÁC KHÁI NI
N
-
-
-
-
truy
-
i dir2
-
2
BÀI 1:
QUAN
-
process id).
-
1.2 M T S
L
command
N
h
command - help
man command
ls
ls
a
ls
l
(file)
cd path
path.
cd ~
cd cd ..
hành.
cp
cp
destination_path
mkdir
source_path
BÀI 1:
3
QUAN
mkdir
directoryname
mv
mv source_path destination_path
rm
rm
R
rm filename
touch
T
find
filename
path: find path name filename
locate
touch filename
filename: locate filename
cat
cat
màn hình: cat filename
less
pageUp, pageDown. Dùng phím q
less filename
grep
grep string filename
sort
sort
filename
bzip2 (*.bz2
bunzip2
bunzip2
filename.bz2
gunzip
unzip
tar
date
Xem thông tin df h
free
gzipped (*.gz): gunzip
filename.gz
(*.zip): unzip filename.zip
.tar, .tar.gz: Ví
tar xvf filename.tar và tar xvzf
filename.tar.gz
4
BÀI 1:
QUAN
history
hostname
pwd
hành.
rwho -a
network.
uptime
who
máy.
whoami
ps
ps
aux
top
command &
command
fg
trình
bg
kill pid
-z.
pid
killall -9 name
nice program level
1.3 PHÂN QUY N B O V
1.3.1 Quy n t p tin
ps.
name
program
nice
VÀ TRUY XU T FILE
level.
BÀI 1:
QUAN
5
owner, group, other
read, write, execute}.
r: Read
w: Write
x: Execute
-: None
chmod
chmod [-R] mode file
-
(Operation)
u
g (group
nhóm)
o (other
=
r (read
+
w (write - ghi)
-
x (execute
a (all
$ chmod u+rx-w /tmp
$ chmod
R u+rwx,g+r-w,o-rwx /tmp
$ chmod a=rx abc.txt
-
owner
(nhóm) và
other
group
6
BÀI 1:
QUAN
4
2
1
u, o
0
000
- --
1
001
- -x
2
010
- w-
3
011
-wx
4
100
r--
5
101
r -x
6
110
r w-
7
111
r wx
g)
khơng có
$ chmod 751 abc.txt
C
read, write, và execute (4+2+1=7), group
owner
read và execute (4+1=5), và other
1.3.2
i ch
s
execute (1).
h u
chown [options] new_owner object(s)
trong
1.3.3
(-R)
i nhóm s
chown.VD: chown
R user1 /test
h u
chgrp [options] new_group object(s)
(-R)
chgrp. VD: chgrp
R group1 /test
BÀI 1:
1.4
7
QUAN
U KHI N TI N TRÌNH
1.4.1 Xem thơng tin v ti n trình
ps
$ps
PID
128
137
235
TTY
TIME
tty1 00:00:00
pts/9 00:00:00
pts/0 00:00:00
CMD
bash
mc
bash
ps
Del
Ctrl
ps
a
1.4.2 Ti n trình ti n c nh
#
$
ls
$ls
R /
1.4.3 Ti n trình h u c nh
&
&
R
Alt
8
BÀI 1:
QUAN
$ls R / &
[1] 23978
$
$
[1] Done
ls
R
1.4.4 T m d ng ti n trình
Ctrl
Z
Ctrl
$ls R / >allfiles.txt
^Z
[1]+ Stopped ls R / >allfiles.txt
$
ps
1.4.5
c ti n trình
jobs
$jobs
[1]+ Stopped ls
R / >allfiles.txt
jobs
[1]
bg.
$bg 1
ls
R / >allfiles.txt
$jobs
[1]+ Running ls
R />allfiles.txt &
af
Z
BÀI 1:
9
QUAN
fg
$fg 1
ls
R / >allfiles.txt
1.4.6 H y ti n trình
kill
h này, kill
kill
ps
af
ps
af
kill.
$ls
R / >data.txt
^Z
$ps -af
PID TTY
TIME
CMD
128 tty1
00:00:00
bash
137 pts/9 00:00:00
ls -R
235 pts/0 00:00:00
bash
$kill 137
$ps -af
PID TTY
TIME
CMD
128 tty1
00:00:00
bash
235 pts/0 00:00:00
bash
kill
$kill -9 137
-
10
BÀI 1:
QUAN
Bài 1:
home
dsl
CTH
user1
user2
mkdir
Bài 2:
user1 -
test1.c, test2.c
test3.c, test4.c
user2
touch:
$touch test1.c
test2.c, test3.c, test4.c
touch
vi
BÀI 1:
QUAN
11
cat
cat
Ctrl+D
Bài 3:
-
test3.c
-
user2 sang user1
user1 và user2
test3.c, test4.c
/user1
$cp test3.c test4.c ../user1
$cp *.c /user1
R
cp
$cp
R /mydata /tmp
/mydata
/tmp
12
BÀI 1:
QUAN
Bài 4:
-
user2 sang user1
test4.c
-
user1 và user2
test4.c
test4.doc
$mv test4.c test4.doc
.doc và .c
/tmp
$mv *.doc *.c /tmp
user1
là NewDir
user2
mv
$mv user1/ user2/NewDir
Bài 5:
.tar:
-
test3.c
-
user2
user2
test3.c
-
test3.c.tar
Bài 6:
rm, rmdir
test3.c.tar
BÀI 1:
QUAN
13
rmdir
r
-
test3.c, test3.c.tar t
-
user2
-
user1
rm.
user2
Bài 7:
-
user1
-
user1 và root
-
group1
user1 vào nhóm group1
/baitap1
-
770
user1
test.txt
/baitap1
Bài 8:
-
ketqua.txt
-
ls -lR /
/ và
ketqua.txt.
-
ketqua.txt
14
BÀI 2:
THI
BÀI 2:
2.1 GI I THI U
2.1.1
-
-
gcc
/usr/bin
/usr/local/bin
which gcc
gcc
/usr/include hay
/usr/local/include
/lib
gcc
/usr/local/lib
gcc
/usr/lib/gcc-lib.
2.1.2 Các t
/usr/include h
/usr/include/sys
-
/usr/include/X11
/usr/include/g++-2
-
g++.
Tuy nhiên
I
BÀI 2:
$ gcc
-
I/usr/mypro/include test.c
THI
15
otest
Khi chúng
man
man
types.h và
kill()
signal.h.
2.1.3 Các t
n
-
.a, .so, .sa
libutil.a hay libc.so
lib
-
.so
ls /usr/lib
ls /lib
ld
/usr/lib và /lib
sau:
$ gcc test.c
otest /usr/lib/libm.a
lib
.so
.a
l
$ gcc test.c
C
otest -lm
gcc
lib và tìm libm.a
l
libm.so
-
gcc
L
16
BÀI 2:
$ gcc test.c
THI
otest -L/usr/myproj/lib -ltool
libtool.a
libtool.so
/usr/myproj/lib.
2.1.4
n liên k t trên Linux
-
.o
c
$gcc
c helloworld.c
helloworld.o
$gcc helloworld.o
o helloworld
-
ld
c
2.1.4.1
n liên k
th
/* cong.c */
int cong( int a, int b )
{
return a + b;
}
BÀI 2:
THI
/* nhan.c */
long nhan( int a, int b )
{
return a * b;
}
.o
$ gcc
c cong.c nhan.c
.h
/* lib.h */
int cong( int a, int b );
long nhan( int a, int b );
program.c
/* program.c */
#include <stdio.h>
#include "lib.h"
int main ()
{
int a, b;
printf( "Nhap vào a : " );
scanf( "%d", &a );
printf("Nhap vào b : " );
scanf( "%d", &b );
printf(
\n", a, b, cong( a, b ) );
printf( "Tich %d * %d = %ld\n", a, b, nhan( a, b ) );
return ( 0 );
}
$ gcc
c program.c
$ gcc program.o cong.o nhan.o -oprogram
17