15,440
社区成员
发帖
与我相关
我的任务
分享
//File.c
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <syslog.h>
#include <string.h>
#include <stdlib.h>
#include <wchar.h>
void menu(void);
void PIF(void);
void SIF(void);
void MIF(void);
void BIF(void);
int main()
{
int choose;
menu();
scanf("%d", &choose);
while(choose != 0)
{
switch(choose)
{
case 1: PIF();
break;
case 2: SIF();
break;
case 3: MIF();
break;
case 4: BIF();
break;
default: printf("**************没有该选项,请重新输入**************\n");
}
menu();
scanf("%d", &choose);
}
return 0;
}
viod menu(void)
{
printf("***************************************\n")
printf("*********亲爱的用户请输出您需要的操作*********\n")
printf("**************1.查看进程信息**************\n")
printf("**************2.查看系统信息**************\n")
printf("**************3.查看内存资源**************\n")
printf("**************4.查看模块信息**************\n")
printf("**************0.退出该系统****************\n")
printf("***************************************\n")
printf("**************请输入1-4*******************\n")
}
void PIF(void)
{
char *pa = "/usr/bin/x11/top";
char *arg[4] = {"top", NULL};
if(fork()==0)
{
printf("****现在正在进入进程信息界面****\n");
execv(pa, arg);
printf("ps:在该界面你可以输入k进行杀死进程,输入k之后再输入进程编号(PID)号\n")
printf("ps:如果你想要退出该界面,可以输入q进行退出\n")
}
else
{
wait(0); //
}
}
void SIF(void)
{
printf("-------------------------------------\n");
printf("***系统信息如下***\n");
printf("-------------------------------------\n");
if(fork()==0)
{
execlp("/bin/cat", "cat", "/proc/version", NULL);
}
else
{
wait(0); //
}
printf("-------------------------------------\n");
printf("***处理器信息如下***\n");
printf("-------------------------------------\n");
if(fork()==0)
{
execlp("/bin/cat", "cat", "/proc/cpuinfo", NULL);
}
else
{
wait(0); //
}
}
void MIF(void)
{
printf("-------------------------------------\n");
printf("***有关内存的信息如下***\n");
printf("-------------------------------------\n");
if(fork()==0)
{
execlp("/bin/cat", "cat", "/proc/meminfo", NULL);
}
else
{
wait(0); //
}
}
void BIF(void)
{
printf("-------------------------------------\n");
printf("***所有模块信息如下(谨慎卸载)***\n");
printf("-------------------------------------\n");
char *path = "/bin/lsmod";
char **argv[4] = {"lsmod", NULL};
if(fork()==0)
{
execv(path, argv);
}
else
{
wait(0); //
}
printf("-------------------------------------\n");
char name[1024];
printf("***请输入您所需要卸载的模块名***\n");
scanf("%s", name);
char *pa = "/sbin/rmmod";
char *ar[4] = {"rmmod", name, NULL};
if(fork()==0)
{
execlp(pa, ar);
}
else
{
wait(0); //
}
print("卸载成功!\n");
}