您的位置:首页 > 运维架构 > Linux

测试linux下一些最基本的服务情况的方法

2012-07-02 17:06 543 查看
1、进程管理

1.1 创建进程

#include <stdlib.h> //Standard library definitions

#include <unistd.h> //Standard symbolic constants and types

int main(int argc, char *argv[])

{

pid_t pid; //Define a variable.

pid=fork(); //Create a new process.

if(pid==0) //Child process

printf("I'm the child.\n"); //Display a message.

else if(pid>0) //parent process

printf("I'm the parent.\n"); //Display a message.

else

{

perror("fork"); //Call fork() failed.

exit(1); //Exit function.

}

printf("call fork success!\n"); //Display a success message.

exit(0); //Exit function.

}

2. 在当前目录下执行:

gcc -o fork fork.c

./fork

期望:1. 步骤2后,终端输出:

I'm the parent.

call fork success!

#I'm the child.

call fork success!

1.2终止进程

操作步骤:

1. 创建文件exit.c,文件内容如下:

#include <stdio.h> //Standard buffered input/output

#include <stdlib.h> //Standard library definitions

#include <unistd.h> //Standard symbolic constants and types

int main(int argc, char *argv[])

{ pid_t pid; //Define a variable.

printf("Just 1 process now.\n");

printf("Calling fork()...\n");

pid=fork(); //Create a new process.

if(pid==0) //Child process

{

printf("I'm the child.\n"); //Display a message.

execl("/bin/ls","ls","-l","exit01.c",0); //Calling exec()

perror("exec"); //Give a error message.

exit(1); //Child process terminate, and the status'value is returned to the parent.

}

else if(pid>0) //parent process

{

wait(0); //Wait the child process terminated.

printf("I'm the parent.\n"); //Display a message.

}

else

{

perror("fork"); //Call fork() failed.

exit(1); //Exit function.

}

printf("Calling fork() success!\n"); //Display a success message.

exit(0); //Exit function.

}

2. 在当前目录下执行:

gcc -o exit exit.c

./exit

期望:步骤2后,终端显示:

Just 1 process now.

Calling fork()...

I'm the child.

-rw-r--r-- 1 root root 1068 2005-11-08 exit01.c #需要文件先存在,不然会报无法访问

I'm the parent.

Calling fork() success!

2、锁住全部地址空间

#include <stdio.h> //Standard buffered input/output

#include <stdlib.h> //Standard library definitions

#include <errno.h> //System error numbers.

#include <sys/mman.h> //memory management declarations

int main()

{

int ret; //Define variable

ret=mlockall(MCL_CURRENT|MCL_FUTURE); //Calling mlockall() to lock pages

if(ret==0)

{

printf("calling mlockall() success.\n"); //Display a success message.

if(munlockall()==0) //Calling munlockal() to unlock pages

{

printf("calling munlockall() success.\n"); //Display a success message.

}else {

perror("munlockall"); //Give a error message.

exit(1); //Exit function

}

}

else {

perror("mlockall"); //Give a error message.

exit(1); //Exit function

}

}

2. 在当前目录下执行:

gcc -o lockall lockall.c

./lockall

期望:1. 步骤2后,终端显示:

calling mlockall() success.

calling munlockall() success.

3、网络服务测试

3.1验证apache服务是否安装

1. 打开终端,执行命令

#rpm -qa |grep http

期望:1. 显示 安装了以下软件包(或类似包):

libcommons-httpclient-java-3.1-10

libmicrohttpd3-0.2.1-lmdv2008.1

httpd-......等

2、启动/停止/重启/状态等关于apache服务

1. 在终端下执行命令

# service httpd start / stop / restart 等

2. 在终端下执行命令

# service httpd status

3.2 SSH服务-验证

1. root用户在系统的字符终端下执行命令

service sshd start / stop / restart 等

2. 使用同一局域网主机,终端执行命令:

ssh root@server-ip

根据提示,输入密码

期望:1. 步骤1后,终端显示启动服务成功

2. 步骤2后,登入server端,字符终端切换为server主机

3.3 NFS服务-搭建NFS服务器

root用户在系统的字符终端下执行命令

#service nfs restart / stop / restart 等

停止nfs服务,终端执行命令:

/etc/init.d/nfs stop
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: