#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pthread.h>
#define LOG_FILE_NAME "./log_file.txt"
FILE *Fd1 = 0;
void SetFileHeader(void)
{
long len = 0;
len = ftell(Fd1);
if (len > 10000)
{
fseek(Fd1, 0, SEEK_SET);
}
}
void OpenFile(void)
{
Fd1 = fopen(LOG_FILE_NAME, "w+");
if (Fd1 != NULL)
{
SetFileHeader();
fprintf(Fd1, "faied to open!\n");
}
else
{
exit(-1);
}
}
void CloseFile(void)
{
fclose(Fd1);
}
void *func1(void *arg)
{
while(1)
{
SetFileHeader();
fprintf(Fd1, "this is 1 test!\n");
}
}
void *func2(void *arg)
{
while(1)
SetFileHeader();
fprintf(Fd1, "this is 2 test!\n");
}
}
void *func3(void *arg)
{
while(1)
{
SetFileHeader();
fprintf(Fd1, "this is 3 test!\n");
}
}
void *func4(void *arg)
{
while(1)
{
SetFileHeader();
fprintf(Fd1, "this is 4 test!\n");
}
}
void *func5(void *arg)
{
while(1)
{
SetFileHeader();
fprintf(Fd1, "this is 5 test!\n");
}
}
void *func6(void *arg)
{
while(1)
{
SetFileHeader();
fprintf(Fd1, "this is 6 test!\n");
}
}
void *func7(void *arg)
{
while(1)
{
SetFileHeader();
fprintf(Fd1, "this is 7 test!\n");
}
}
int main(int argc, char **argv)
{
int ret = 0;
OpenFile();
if (argc == 1)
{
printf("just an a,out!\n");
}
else if ((argc == 2) && (argv[1][0] == '1'))
{
printf("argv[1][0] = %c\n", argv[1][0]);
}
else
{
printf("argc = %d, argv[1][0] = %c\n", argc, argv[1][0]);
}
pthread_t t1;
pthread_t t2;
pthread_t t3;
pthread_t t4;
pthread_t t5;
pthread_t t6;
pthread_t t7;
pthread_create(&t1, NULL, func1, NULL);
pthread_create(&t2, NULL, func2, NULL);
pthread_create(&t3, NULL, func3, NULL);
pthread_create(&t4, NULL, func4, NULL);
pthread_create(&t5, NULL, func5, NULL);
pthread_create(&t6, NULL, func6, NULL);
pthread_create(&t7, NULL, func7, NULL);
while(1)
{
sleep(1);
}
CloseFile();
}