http://blog.csdn.net/xcl119xcl/article/details/6864524
1.编写一个程序,写时间到文件中
#ifdef WIN32
#include <windows.h>
#include <time.h>
#endif
#include <unistd.h>
#include <string>
#include <stdio.h>
using namespace std;
int main()
{
while(1)
{
FILE *fr;
fr=fopen("abc.txt","a+");
if(fr==NULL)
{
printf("File not open!\n");
break;
}
else
{
printf("File ok!\n");
}
time_t timer;
struct tm *tblock;
timer=time(NULL);
tblock=localtime(&timer);
string tmpTime = asctime(tblock);
printf("Local time is: %s",tmpTime.c_str());
fwrite(tmpTime.c_str(), tmpTime.size(), 1, fr);
fclose(fr);
sleep(5);
}
return 0;
}
2.gcc -o test main.cpp -lstdc++
3.nohup ./test
4.查看结果 tail -f abc.txt
之后,关闭Scrt
4.ps -A
可以看到所有进程,包括这个test
5.kill -9 进程号