Linux编程常用
2016-05-12 20:41
477 查看
获取时间
#include <sys/time.h> Linux系统的日期时间头文件。比如:
structtimeval tv;gettimeofday(&tv,NULL);ftime()。
#include <time.h> C/C++中的日期和时间头文件。比如:
char strtime[1024] = {0};
time_t now;
struct tm *ptm;
time(&now);
ptm = localtime(&now);
sprintf(strtime, "%d%02d%02d%02d%02d%02d", ptm->tm_year+1900,ptm->tm_mon+1,ptm->tm_mday,ptm->tm_hour,ptm->tm_min,ptm->tm_sec);
开机后台运行
可以通过增加一个(&)符号,将应用程序在后台启动。如:/path/to/yourprogram &
监控狗
如下,每隔5秒检查CardPlatform进程是否存在,不存在,就开启。
#!/bin/sh
echo "enter shell" >> /usr/local/zf/CardPlatform/log
while true;do
count=`ps -e | grep CardPlatform|grep -v grep`
if [ "$?" != "0" ];then
echo "start " >> /usr/local/zf/CardPlatform/log
echo ">>>>CardPlatform isnot runing..."
/usr/local/zf/CardPlatform/CardPlatform
else
echo "running " >> /usr/local/zf/CardPlatform/log
echo ">>>>CardPlatformis runing..."
fi
sleep 5
done
打印堆栈
#include <execinfo.h>
FILE* fp = fopen("/home/3.txt","ab");
if(fp)
{
void *bt[20];
char **strings;
size_t sz;
sz = backtrace(bt, 20);
strings = backtrace_symbols(bt, sz);
for(int i = 0; i < sz; ++i)
fprintf(fp,"%s\n", strings[i]);
fclose(fp);
}
#include <sys/time.h> Linux系统的日期时间头文件。比如:
structtimeval tv;gettimeofday(&tv,NULL);ftime()。
#include <time.h> C/C++中的日期和时间头文件。比如:
char strtime[1024] = {0};
time_t now;
struct tm *ptm;
time(&now);
ptm = localtime(&now);
sprintf(strtime, "%d%02d%02d%02d%02d%02d", ptm->tm_year+1900,ptm->tm_mon+1,ptm->tm_mday,ptm->tm_hour,ptm->tm_min,ptm->tm_sec);
开机后台运行
可以通过增加一个(&)符号,将应用程序在后台启动。如:/path/to/yourprogram &
监控狗
如下,每隔5秒检查CardPlatform进程是否存在,不存在,就开启。
#!/bin/sh
echo "enter shell" >> /usr/local/zf/CardPlatform/log
while true;do
count=`ps -e | grep CardPlatform|grep -v grep`
if [ "$?" != "0" ];then
echo "start " >> /usr/local/zf/CardPlatform/log
echo ">>>>CardPlatform isnot runing..."
/usr/local/zf/CardPlatform/CardPlatform
else
echo "running " >> /usr/local/zf/CardPlatform/log
echo ">>>>CardPlatformis runing..."
fi
sleep 5
done
打印堆栈
#include <execinfo.h>
FILE* fp = fopen("/home/3.txt","ab");
if(fp)
{
void *bt[20];
char **strings;
size_t sz;
sz = backtrace(bt, 20);
strings = backtrace_symbols(bt, sz);
for(int i = 0; i < sz; ++i)
fprintf(fp,"%s\n", strings[i]);
fclose(fp);
}
相关文章推荐
- linux相关
- Linux基础之:curl工具的使用
- Linux 设备驱动框架
- Linux监控cpu以及内存使用情况之top命令
- CentOS 6.5自动化运维之基于DHCP和TFTP服务的PXE自动化安装centos操作系统详解
- CentOS 6.5自动化运维之基于DHCP和TFTP服务的PXE自动化安装centos操作系统详解
- Kafka在Centos6.4中的集群搭建
- linux 查看文件系统类型
- Linux安装LAMP开发环境及配置文件管理
- python ssh到linux
- C++程序windows To linux移植经验案例
- CentOS卸载OpenJDK
- Linux驱动调试中的Debugfs的使用简介
- CentOS搭建NTP服务器
- error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
- linux批量远程管理主机命令 parallel-ssh, parallel-scp, parallel-nuke, parallel-slurp, parallelrsyncp
- linux find命令
- Linux 右键菜单(添加新建文件选项)
- 修改Linux图标
- linux之sed用法