linux如何定时监控进程状态

linux如何定时监控进程状态,第1张

大概就是写一个脚本, 脚本的样子大概如下就可以了, 你给完善一下

#!/bin/bash

ps 1>>pslog.txt

top 1>>toplog.txt

然后用crontab -e 这个命令 就是用vim编辑一下

比如 */5 * * * * /home/你的名字/脚本名字.sh

这样就是每隔5分钟执行一次脚本这个脚本.

*/5(分钟) *(小时) *(日期) *(月份) *(星期几)

明白了吗?

列出后台进程命令:jobs

后接&:将程序放到后台执行,如,bash test.sh&

fg <num>:将后台进程调到前台,如,fg 1

ctrl+z 可挂起进程,注:jobs显示的状态是stopped

bg <num>可将进程在后台执行,比如执行ctrl+z挂起进程后,再用命令bg 1让进程在后台继续执行

语法:crontab [-u user] [-l | -r | -e]

ping的作用:连通性检查以及网速检查

ping -c 测试数据包数量 目的主机地址

如:ping -c 5 www.baidu.com

注:立即生效需要重启网卡:service network restart

ssh 用户名@ip地址

#include <sys/io.h>

#include <sys/ipc.h>

#include <sys/timeb.h>

#include <sys/shm.h>

#include <sys/sem.h>

#include <sys/sysinfo.h>

#include <stdio.h>

#include <string.h>

#include <sys/ioctl.h>

#include <sys/time.h>

#include <fcntl.h>

#include <unistd.h>

#include <stdlib.h>

#include <errno.h>

#include <time.h>

#include <sys/ipc.h>

#include <sys/types.h>

#include <sys/stat.h>

#include <sys/msg.h>

void CheckPid(void)

{

pid_t termpid

int flags

termpid = waitpid(-1,&flags,WNOHANG)

if (termpid>0)

{

msglog.code = LOG_MSG_OTHER

if(WIFEXITED(&flags))

{

printf("pid=%d的子进程正常结束,返回信息=%d,结束状态=%d\n",termpid,flags,WEXITSTATUS(&flags))

}

else if(WIFSIGNALED(&flags))

{

printf("pid=%d的子进程异常终止,返回信息=%d,终止进程的信号的编号=%d\n",termpid,flags,WTERMSIG(&flags))

}

else if(WIFSTOPPED(&flags))

{

printf("pid=%d的子进程暂停,返回信息=%d,暂停进程的信号的编号=%d\n",termpid,flags,WSTOPSIG(&flags))

}

else

{

printf_d(cur_dep,SYS_PID_DSC_OUTTYPE,"pid=%d的子进程退出",termpid)

}

}

}

其中“返回信息”flags的返回值有几种情况,如段错误、正常终止、 被信号终断等


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/8320016.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-15
下一篇2023-04-15

发表评论

登录后才能评论

评论列表(0条)

    保存