From 0ce7424fa11801eae965c16f80102b161748c41c Mon Sep 17 00:00:00 2001 From: guo_peixu Date: Thu, 16 Jun 2022 17:11:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E8=B4=B9=E8=80=85=E8=BF=9B=E7=A8=8B?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E6=97=B6=EF=BC=8C=E6=A3=80=E6=9F=A5=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E5=AD=98=E5=9C=A8=E5=B7=B2=E5=90=AF=E5=8A=A8=E7=9A=84?= =?UTF-8?q?=E6=B6=88=E8=B4=B9=E8=80=85=E8=BF=9B=E7=A8=8B=EF=BC=8C=E9=81=BF?= =?UTF-8?q?=E5=85=8D=E9=87=8D=E5=A4=8D=E5=90=AF=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shm_consumer/MESA_shm_consumer.c | 45 +++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/shm_consumer/MESA_shm_consumer.c b/shm_consumer/MESA_shm_consumer.c index 486b7b3..a64096e 100644 --- a/shm_consumer/MESA_shm_consumer.c +++ b/shm_consumer/MESA_shm_consumer.c @@ -10,6 +10,7 @@ #include "MESA_shm_ring_queue.h" +#define BUFSIZE 256 void init_ring_queue_head_arrray(struct MESA_shm_overview *ovw, struct MESA_shm_queue_head **ring_queue_head) { int i = 0; @@ -57,8 +58,50 @@ void consumer_daemo() } return ; } -int main(int argc, char **args) +int consumer_is_running(char *process_name) { + FILE *fp = NULL; + char buf[BUFSIZE] = {0}; + int count = 0; + char command[BUFSIZE] = {0}; + if(process_name == NULL){ + return 0; + } + snprintf(command, sizeof(command), "ps -ef | grep %s | grep -v grep | wc -l", process_name); + fp = popen(command, "r"); + if(fp == NULL){ + return 0; + } + if((fgets(buf, sizeof(buf), fp)) != NULL){ + count = atoi(buf); + } + pclose(fp); + if(count > 1){ + return 1; + }else{ + return 0; + } + return 0; +} +char *get_exe_name(char *argv) +{ + char * p = NULL; + p = rindex(argv, '/'); + if(p == NULL){ + p = argv; + }else{ + p = p + 1; + } + return p; +} +int main(int argc, char **argv) +{ + + char *exe_name = get_exe_name(argv[0]); + if(consumer_is_running(exe_name)){ + printf("consumer process is already running\n"); + return 0; + } consumer_daemo(); int i = 0; struct MESA_shm_overview *shm_overview = NULL;