Linux实验报告-中南大学-胡小龙

更新时间:2024-04-16 20:37:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

Unix/Linux实验报告

中南大学信息科学与工程学院

实验一 Linux的安装(课后)

1、实验目的

(1) 了解硬盘分区的概念和方法; (2) 掌握硬盘的分区规划;

(3) 掌握Linux操作系统的安装和配置过程。 2、实验设备

一台pc机、RedHat Linux 7.2以上版本、VMware Workstation v5.5 3、实验原理

Linux可以以多种方式安装在PC机上: (1)独立分区安装、 (2)DOS分区安装和 (3)虚拟机VMWare下安装。鉴于VMware下安装对原来系统影响较小且不影响本实验目的,因此采用VMWare下安装方式。 4、实验步逐

(1) 在Windows XP下安装VMware 5.5 (2) 配置虚拟机 (3) 启动虚拟机 (4) 启动Linux安装过程 (5) 安装过程配置 (6) 安装后配置

(7) 第1次启动 VMWare下Linux操作系统 5、实验记录

(1) 记录详细安装过程

(2) 安装过程中出现的问题及其解决措施 Linux安装: (1)语言选择:

(2)键盘配置:

(3)鼠标配置:

(4)选择安装还是升级:

(5)安装类型:

(6)磁盘分区设置:

(7)为系统分区:

(8)添加分区:

(9)引导装载程序配置:

(10)网络配置:

(11)防火墙配置:

(12)语言支持的选择:

(13)时区配置:

(14)设置根口令

(15)选择软件包组:

(16)准备安装:

应该看到一个安装 Red Hat Linux 做准备的屏幕。 当你重新引导系统后,一份完整的安装日志可在 /root/install.log 中找到,以备今后参考。要取消安装进程,按计算机的重新启动按钮,或者使用 [Control]-[Alt]-[Delete] 组合键来重启计算机。

(17)安装软件包:

(18)创建引导盘:

(19)视频卡配置:

(20)配置显示器:

(21)定制配置:

(22)安装完成

实验2 Linux基本操作 1、实验目的

(1)复习Linux基本命令。 (2)掌握常用Linux命令 2、实验内容

(1)练习命令行模式下的常用命令:

man:命令帮助

ALT-Fx:虚终端切换

常用命令:cat、Ls、ps、chmod、kill、ln、cp、mv、rm、cd、pwd、mkdir、chown、who、w、wc、whoami、date、uname等 命令实例:

root@soamazing-desktop:~# touch test root@soamazing-desktop:~# cat test aaaaa

root@soamazing-desktop:~# ls

test 公共的 模板 视频 图片 文档 下载 音乐 桌面 root@soamazing-desktop:~# ps man PID TTY STAT TIME COMMAND

753 tty7 - 0:10 /usr/bin/X :0 -nr -verbose -auth /var/run/gdm/auth-fo - - Ss+ 0:10 - 1081 pts/0 - 0:00 bash - - Ss 0:00 -

1138 pts/0 - 0:00 ps man - - R+ 0:00 - root@soamazing-desktop:~# ls -l total 36

-rw-r--r-- 1 root root 6 2011-04-12 22:20 test drwxr-xr-x 2 root root 4096 2011-04-12 15:40 公共的 drwxr-xr-x 2 root root 4096 2011-04-12 15:40 模板 drwxr-xr-x 2 root root 4096 2011-04-12 15:40 视频 drwxr-xr-x 2 root root 4096 2011-04-12 15:40 图片 drwxr-xr-x 2 root root 4096 2011-04-12 15:40 文档 drwxr-xr-x 2 root root 4096 2011-04-12 15:40 下载 drwxr-xr-x 2 root root 4096 2011-04-12 15:40 音乐 drwxr-xr-x 2 root root 4096 2011-04-12 15:40 桌面 root@soamazing-desktop:~# chmod 888 test chmod: invalid mode: `888'

Try `chmod --help' for more information. root@soamazing-desktop:~# chmod --help Usage: chmod [OPTION]... MODE[,MODE]... FILE... or: chmod [OPTION]... OCTAL-MODE FILE... or: chmod [OPTION]... --reference=RFILE FILE... Change the mode of each FILE to MODE.

-c, --changes like verbose but report only when a change is made

--no-preserve-root do not treat `/' specially (the default) --preserve-root fail to operate recursively on `/' -f, --silent, --quiet suppress most error messages

-v, --verbose output a diagnostic for every file processed --reference=RFILE use RFILE's mode instead of MODE values -R, --recursive change files and directories recursively

--help display this help and exit

--version output version information and exit

Each MODE is of the form `[ugoa]*([-+=]([rwxXst]*|[ugo]))+'.

Report chmod bugs to bug-coreutils@gnu.org

GNU coreutils home page: General help using GNU software: Report

chmod

translation

bugs

to

root@soamazing-desktop:~# ls -l total 36

-rw-r--r-- 1 root root 6 2011-04-12 22:20 test drwxr-xr-x 2 root root 4096 2011-04-12 15:40 公共的 drwxr-xr-x 2 root root 4096 2011-04-12 15:40 模板 drwxr-xr-x 2 root root 4096 2011-04-12 15:40 视频 drwxr-xr-x 2 root root 4096 2011-04-12 15:40 图片 drwxr-xr-x 2 root root 4096 2011-04-12 15:40 文档 drwxr-xr-x 2 root root 4096 2011-04-12 15:40 下载 drwxr-xr-x 2 root root 4096 2011-04-12 15:40 音乐 drwxr-xr-x 2 root root 4096 2011-04-12 15:40 桌面 root@soamazing-desktop:~# chmod u-w,g+w,o+w test root@soamazing-desktop:~# ls -l total 36

-r--rw-rw- 1 root root 6 2011-04-12 22:20 test drwxr-xr-x 2 root root 4096 2011-04-12 15:40 公共的 drwxr-xr-x 2 root root 4096 2011-04-12 15:40 模板 drwxr-xr-x 2 root root 4096 2011-04-12 15:40 视频 drwxr-xr-x 2 root root 4096 2011-04-12 15:40 图片 drwxr-xr-x 2 root root 4096 2011-04-12 15:40 文档

drwxr-xr-x 2 root root 4096 2011-04-12 15:40 下载 drwxr-xr-x 2 root root 4096 2011-04-12 15:40 音乐 drwxr-xr-x 2 root root 4096 2011-04-12 15:40 桌面 root@soamazing-desktop:~# chmod u+w,g-w,o-w test root@soamazing-desktop:~# ls -l total 36

-rw-r--r-- 1 root root 6 2011-04-12 22:20 test drwxr-xr-x 2 root root 4096 2011-04-12 15:40 公共的 drwxr-xr-x 2 root root 4096 2011-04-12 15:40 模板 drwxr-xr-x 2 root root 4096 2011-04-12 15:40 视频 drwxr-xr-x 2 root root 4096 2011-04-12 15:40 图片 drwxr-xr-x 2 root root 4096 2011-04-12 15:40 文档 drwxr-xr-x 2 root root 4096 2011-04-12 15:40 下载 drwxr-xr-x 2 root root 4096 2011-04-12 15:40 音乐 drwxr-xr-x 2 root root 4096 2011-04-12 15:40 桌面 root@soamazing-desktop:~# ln ln: missing file operand

Try `ln --help' for more information. root@soamazing-desktop:~# ln --help

Usage: ln [OPTION]... [-T] TARGET LINK_NAME (1st form) or: ln [OPTION]... TARGET (2nd form) or: ln [OPTION]... TARGET... DIRECTORY (3rd form) or: ln [OPTION]... -t DIRECTORY TARGET... (4th form)

In the 1st form, create a link to TARGET with the name LINK_NAME. In the 2nd form, create a link to TARGET in the current directory. In the 3rd and 4th forms, create links to each TARGET in DIRECTORY. Create hard links by default, symbolic links with --symbolic. When creating hard links, each TARGET must exist. Symbolic links can hold arbitrary text; if later resolved, a relative link is interpreted in relation to its parent directory.

Mandatory arguments to long options are mandatory for short options too.

--backup[=CONTROL] make a backup of each existing destination file

-b like --backup but does not accept an argument

-d, -F, --directory allow the superuser to attempt to hard link directories (note: will probably fail due to

system restrictions, even for the superuser)

-f, --force remove existing destination files -n, --no-dereference treat destination that is a symlink to a directory as if it were a normal file -i, --interactive prompt whether to remove destinations -s, --symbolic make symbolic links instead of hard links -S, --suffix=SUFFIX override the usual backup suffix

-t, --target-directory=DIRECTORY specify the DIRECTORY in which to create

the links

-T, --no-target-directory treat LINK_NAME as a normal file -v, --verbose print name of each linked file --help display this help and exit

--version output version information and exit The

backup

suffix

is

`~',

unless

set

with

--suffix

or

SIMPLE_BACKUP_SUFFIX.

The version control method may be selected via the --backup option or through

the VERSION_CONTROL environment variable. Here are the values:

none, off never make backups (even if --backup is given) numbered, t make numbered backups

existing, nil numbered if numbered backups exist, simple otherwise simple, never always make simple backups

Report ln bugs to bug-coreutils@gnu.org

GNU coreutils home page: General help using GNU software: Report ln translation bugs to root@soamazing-desktop:~# who

root tty7 2011-04-12 22:11 (:0) root pts/0 2011-04-12 22:12 (:0.0) root@soamazing-desktop:~# whoami root

root@soamazing-desktop:~#

(2) 编辑器vi的使用:使用vi建立并修改一个文本文件

root@soamazing-desktop:~# vi test

(3) 档案管理

rpm、gzip、tar等命令

(4) 网络命令

telnet、ftp、talk

,

3、实验记录

(1) 在实验过程中,注意记录实验现象 (2) 使用过程体会、心得、技巧

实验3 Linux系统管理 1、实验目的

(1)掌握Linux基本系统管理命令 (2)掌握基本管理方法

(3)初步了解Linux中与系统管理相关的有关配置文件 2、实验内容

(1) 用户管理

adduser、useradd、passwd等 观察:/etc/passwd文件

(2) 文件系统管理

df、du命令使用

mount、umount命令使用:安装usb盘或者光盘,查看分析/etc/fstab文件

(3) 存储器

free:了解存储器使用情况

(4) 关机

halt、shutdown –h、init 0 reboot、shutdown -r now 并比较它们之间的差别

Halt实际上调用了shutdown -h,shutdown命令安全地将系统关机 ,-h指定延时时间,init 0改变的是系统的级别。

Reboot调用shutdown。Shutdown -h 指定延时时间。

(5) 网络配置

netconfig的使用

(6)启动配置

/etc/inittab:查看、修改并观察其响应

3、实验记录

(1)在实验过程中,注意记录实验现象 (2)使用过程体会、心得、技巧

实验4 Linux Shell程序设计 1、实验目的

(1)掌握Linux shell程序运行方法 (2)掌握Linux Shell程序基本语法 (3)了解Linux环境变量 (3)编写简单Linux shell程序 2、实验内容

(1) 查看/etc/.profile文件:相当于DOS下autoexe.bat (2) 通配符“*”、“?”、“[]”的使用

$ls [a-c]* 和 $ls [a,m,t]*命令

(3)重定向和管道的使用

ls | more

cat > test.txt

(4) 变量

$lookup=/usr/mydir

$echo $lookup

$export lookup:让进程使用

(5) 编辑并运行以下程序(shell程序控制结构)

1 fortest #!/bin/bash for a in x y z do

echo now a=$a done

2 fortest1

#!/bin/bash for a

do

echo now a=$a done

3 functest

#!/bin/bash setup() { echo setup… } do_date() { date } chgdir() { cd $1 } do_date setup chgdir 4 paramtest #!/bin/bash echo filename:$0 echo arguments:$* echo number arg:$# echo arg2:$2 shift echo number arg:$# echo arg2:$2

set hello,everone echo args:$* echo arg2:$2

5 untiltest #!/bin/bash number=0 until (test $number –gt 5) do echo “ $number” number=`expr $number + 1` done 3、实验要求

(1) 每个shell程序事例运行多遍,并给不同参数 (2) 详细记录程序调试及运行结果

实验5 Linux 高级程序设计 1、实验目的

(1)了解Linux操作系统下应用程序开发流程 (2)掌握gun工具链的使用

(3)了解Linux高级编程技巧(例如IPC机制、系统调用等)

2、实验内容

(1) 编写一个简单的C语言程序,编写Makefile文件。了解编译过程,并用gdb进

行调试。

#include int main(void) {

printf(\}

调试: gcc helloworld.c

a.out

(2) 以下任选其一:

1. 编写一个多进程通信程序,采用Message Queue或shared Memory或者Maped File

机制进行通信

2. 编写一个多线程程序(pthread),实现2程同步互斥

源代码:

#include #include

#define BUFFER_SIZE 16 struct prodcons {

// 缓冲区相关数据结构 int buffer[BUFFER_SIZE]; pthread_mutex_t lock; int readpos, writepos; pthread_cond_t notempty; pthread_cond_t notfull; };

void init(struct prodcons *b) {

pthread_mutex_init(&b->lock, NULL); pthread_cond_init(&b->notempty, NULL); pthread_cond_init(&b->notfull, NULL); b->readpos = 0; b->writepos = 0; }

void put(struct prodcons *b, int data) {

pthread_mutex_lock(&b->lock);

if ((b->writepos + 1) % BUFFER_SIZE == b->readpos) {

pthread_cond_wait(&b->notfull, &b->lock); }

b->buffer[b->writepos] = data; b->writepos++;

if (b->writepos > = BUFFER_SIZE) b->writepos = 0;

pthread_cond_signal(&b->notempty); pthread_mutex_unlock(&b->lock); }

int get(struct prodcons *b)

{

int data;

pthread_mutex_lock(&b->lock); if (b->writepos == b->readpos) {

pthread_cond_wait(&b->notempty, &b->lock); }

data = b->buffer[b->readpos]; b->readpos++;

if (b->readpos > = BUFFER_SIZE) b->readpos = 0;

pthread_cond_signal(&b->notfull); pthread_mutex_unlock(&b->lock); return data; }

#define OVER ( - 1) struct prodcons buffer; void *producer(void *data) { int n;

for (n = 0; n < 10000; n++) {

printf(\put(&buffer, n);

} put(&buffer, OVER); return NULL; }

void *consumer(void *data) { int d; while (1) {

d = get(&buffer); if (d == OVER) break;

printf(\}

return NULL; }

int main(void) {

pthread_t th_a, th_b; void *retval; init(&buffer);

pthread_create(&th_a, NULL, producer, 0); pthread_create(&th_b, NULL, consumer, 0); pthread_join(th_a, &retval); pthread_join(th_b, &retval); return 0; }

3、实验要求

(1) 写出源程序,并编译运行 (2) 详细记录程序调试及运行结果

实验6 Linux内核 1、实验目的

(1)了解Linux操作系内核 (2)掌握内核编译和内核升级方法

(3)了解有关内核编程

2、实验内容

(1) 内核配置和编译(课后完成)

(2) 察看/proc内存文件系统下的文件,写出每个目录内容

(3) 编写一个简单的字符虚拟设备程序(以模块方式编译、加载、使用) 3、实验要求

(1) 给出源程序

(2) 记录调试过程和运行结果

本文来源:https://www.bwwdw.com/article/fzmp.html

Top