Index: /branches/rel_apv_10_7_4/usr/click/bin/system_monitor/process_monitor.c
===================================================================
--- /branches/rel_apv_10_7_4/usr/click/bin/system_monitor/process_monitor.c	(revision 40078)
+++ /branches/rel_apv_10_7_4/usr/click/bin/system_monitor/process_monitor.c	(working copy)
@@ -57,10 +57,11 @@
 #define USTACK_RESTART_TIMES_LIMIT 3
 
 #define SWAP_THRESHOLD	50
-#define MAX_GET_PID_COUNT 10 
+#define MAX_GET_PID_COUNT 10
 
 static int check_process;
 static int check_process_status(pid_t pid, int is_dump);
+static pid_t ustack_restart_pid = 0;
 
 /*
 static int is_dumping(pid_t pid)
@@ -317,6 +318,14 @@
 {
 	pid_t pid;
 
+        // Prevent race conditions during the restart process.
+        if (ustack_restart_pid > 0) {
+                monitor_log(LOG_PROCESS_MONITOR,
+                            "Ustack restart already in progress (pid %d), skip it !!.\n",
+                            ustack_restart_pid);
+                return;
+        }
+
 	pid = fork();
 	if (pid < 0) {
 		monitor_log(LOG_PROCESS_MONITOR, "Failed to restart ustack\n");
@@ -326,6 +335,10 @@
 		global_info_p->ustack_restart_status = USTACK_RESTART_PERMIT;
 		exit(0);
 	} else {
+                ustack_restart_pid = pid;
+                monitor_log(LOG_PROCESS_MONITOR,
+                            "Ustack restart (pid %d)\n",
+                            ustack_restart_pid);
 		return;
 	}
 }
@@ -580,9 +593,9 @@
                         }
                     }
                     if (dump_flag) {
-                        monitor_log(LOG_PROCESS_MONITOR, "Process %s is dumping, ignore ustack restart triggered by swap\n", pptr->name);	
+                        monitor_log(LOG_PROCESS_MONITOR, "Process %s is dumping, ignore ustack restart triggered by swap\n", pptr->name);
                     } else {
-                        monitor_log(LOG_PROCESS_MONITOR, "Swap is used too much, may caused by memery leak, so restart ustack\n");
+                        monitor_log(LOG_PROCESS_MONITOR, "Swap is used too much, may caused by memory leak, so restart ustack\n");
 					    restart_ustack();
                     }
 				}
@@ -595,6 +608,19 @@
 					continue;
 				}
 				cur_time = global_info_p->uptime;
+
+                                /* check if the previous restart is still in progress */
+                                if (ustack_restart_pid > 0) {
+                                        int status;
+                                        pid_t result = waitpid(ustack_restart_pid, &status, WNOHANG);
+                                        if (result > 0 || (result == -1 && errno == ECHILD)) {
+                                                monitor_log(LOG_PROCESS_MONITOR,
+                                                            "Ustack restart finished (pid %d).\n",
+                                                            ustack_restart_pid);
+                                                ustack_restart_pid = 0;
+                                        }
+                                }
+
 				/* detect running process status with kill 0 */
 				for (i = 0; i < MAX_PROCESS; i++) {
 					pptr = proc_list + i;
