文档详情

操作系统inx课程实验报告.doc

发布:2018-09-03约1.2万字共37页下载文档
文本预览下载声明
实验1.1、1.2 Linux Ubuntu的安装、创建新的虚拟机VMWare 实验1.3 Shell编程 1.实验目的与内容 通过本实验,了解Linux系统的shell机制,掌握简单的shell编程技巧。 编制简单的Shell程序,该程序在用户登录时自动执行,显示某些提示信息,如“Welcome to Linux”, 并在命令提示符中包含当前时间、当前目录和当前用户名等基本信息。 2.程序源代码清单 #includestdio.h #includesys/wait.h int main(){ printf(Hello Linux\n); int pid; int state; int pfd[2]; pipe(pfd); if (fork()==0){ printf(In the grep progress\n); dup2(pfd[0],0); close(pfd[0]); close(pfd[1]); execlp(grep,grep,sh,0); perror(exelp grep error); } esle if(fork()==0){ printf(In the ps progress\n); dup2(pfd[1],1); close(pfd[0]); close(pfd[1]); execlp(ps,ps,-ef,0); perror(execlp ps -ef); } close(pfd[1]); close(pfd[0]); wait(state); wait(state); } 实验2.3 内核模块 实验步骤: (1).编写内核模块 文件中主要包含init_clock(),exit_clock(),read_clock()三个函数。其 中init_clock(),exit_clock()负责将模块从系统中加载或卸载,以及增加或删除模块在/proc中的入口。read_clock()负责产生/proc/clock被读时的动作。 (2).编译内核模块Makefile文件 # Makefile under 2.6.25 ifneq ($(KERNELRELEASE),) #kbuild syntax. dependency relationshsip of files and target modules are listed here. obj-m := proc_clock.o else PWD := $(shell pwd) KVER ?= $(shell uname -r) KDIR := /lib/modules/$(KVER)/build all: $(MAKE) -C $(KDIR) M=$(PWD) modules clean: rm -rf .*.cmd *.o *.mod.c *.ko .tmp_versions *.symvers *.order endif 编译完成之后生成proc_clock.ko模块文件。 (3).内核模块源代码clock.c #include linux/kernel.h #include linux/module.h #include linux/proc_fs.h #include linux/string.h #include linux/vmalloc.h #include asm/uaccess.h #define MODULE #define MODULE_VERSION 1.0 #define MODULE_NAME clock struct proc_dir_entry* my_clock; int read_clock(char* page, char** start, off_t off, int count, int* eof, void* data) { int len; struct timeval xtime; do_gettimeofday(xtime); len = sprintf(page, %d %d\n, xtime.tv_sec, xtime.tv_usec); printk(clock: read_func()\n); return len; } struct proc_dir_entry *clock_proc_file; int init_clock(void) { clock_proc_file =create_proc_read_entry(clock,0,NULL,read_clock,NULL); return 0; } void exit_c
显示全部
相似文档