利用共享内存读取系统log
首先定义一个结构体来存储数据
以下是代码(用法和思路)
1 static struct shbuf_ds 2 { 3 int size; // size of data written 4 int head; // start of message list 5 int tail; // end of message list 6 char data[1]; // data/messages 7 } *flashsyslog_buf = NULL, *buf = NULL; // shared memory pointer 8 9 10 11 static struct sembuf SMrup[1] = {{0, -1, IPC_NOWAIT | SEM_UNDO}}; // set SMrup 12 static struct sembuf SMrdn[2] = {{1, 0, 0}, {0, +1, SEM_UNDO}}; // set SMrdn 13 14 15 if (-1 == (flashsyslog_shmid = shmget(FLASHSYSLOG_KEY_ID, 0, 0))) 16 { 17 printf("Syslog disabled or log buffer not allocated "); 18 buffer[0]='