使用进程间共享的信号量,标记消费者进程是否正在运行
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
#include <sys/sem.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
@@ -43,6 +44,8 @@ struct log_file_list g_log_file_list;
|
||||
struct care_pid_list g_care_pid_list;
|
||||
int g_output_mode = CONSUMER_OUTPUT_MODE_FILE;
|
||||
int g_care_pid = CONSUMER_CARE_PID_ALL;
|
||||
int g_semid = -1;
|
||||
|
||||
void init_ring_queue_head_arrray(struct MESA_shm_overview *ovw, struct MESA_shm_queue_head **ring_queue_head)
|
||||
{
|
||||
int i = 0;
|
||||
@@ -52,7 +55,10 @@ void init_ring_queue_head_arrray(struct MESA_shm_overview *ovw, struct MESA_shm_
|
||||
if(tmp_ovw->shmid == -1){
|
||||
break;
|
||||
}
|
||||
ring_queue_head[i] = shmat(tmp_ovw->shmid, NULL, 0);
|
||||
ring_queue_head[i] = shmat(tmp_ovw->shmid, NULL, 0);
|
||||
if(ring_queue_head[i] == (struct MESA_shm_queue_head *)-1){
|
||||
ring_queue_head[i] = NULL;
|
||||
}
|
||||
}
|
||||
return ;
|
||||
}
|
||||
@@ -507,6 +513,30 @@ error:
|
||||
pclose(fp);
|
||||
return -1;
|
||||
}
|
||||
void MESA_shm_sem_p(int semid)
|
||||
{
|
||||
if(g_semid == -1){
|
||||
return ;
|
||||
}
|
||||
struct sembuf sem_b;
|
||||
sem_b.sem_num = 0;
|
||||
sem_b.sem_op = -1;
|
||||
sem_b.sem_flg = SEM_UNDO;
|
||||
semop(semid, &sem_b, 1);
|
||||
return ;
|
||||
}
|
||||
void MESA_shm_sem_v(int semid)
|
||||
{
|
||||
if(g_semid == -1){
|
||||
return ;
|
||||
}
|
||||
struct sembuf sem_b;
|
||||
sem_b.sem_num = 0;
|
||||
sem_b.sem_op = 1;
|
||||
sem_b.sem_flg = SEM_UNDO;
|
||||
semop(g_semid, &sem_b, 1);
|
||||
return ;
|
||||
}
|
||||
|
||||
void print_help(char *exe_name)
|
||||
{
|
||||
@@ -537,6 +567,8 @@ int main(int argc, char **argv)
|
||||
}else{
|
||||
g_cur_tty_fd = get_cur_tty_fd();
|
||||
}
|
||||
g_semid = MESA_shm_alloc_sem();
|
||||
MESA_shm_sem_p(g_semid);
|
||||
int i = 0;
|
||||
struct MESA_shm_overview *shm_overview = NULL;
|
||||
struct MESA_shm_overview *tmp_ovw = NULL;
|
||||
|
||||
Reference in New Issue
Block a user