@@ -42,6 +42,17 @@ bool process_is_running(int app_index)
4242 // Check if the application is running
4343 if (kill (pid , 0 ) == 0 )
4444 {
45+ // Verify process identity by checking start time to prevent PID reuse issues
46+ time_t recorded_start_time = apps_get_array ()[app_index ].start_time ;
47+ time_t current_start_time = get_process_start_time (pid );
48+
49+ if (current_start_time > 0 && recorded_start_time > 0 && current_start_time != recorded_start_time )
50+ {
51+ LOGE ("Process %s PID %d has different start time (PID reused), treating as different process" ,
52+ get_app_name (app_index ), pid );
53+ return false;
54+ }
55+
4556 return true; // Process is running
4657 }
4758 else if (errno == EPERM )
@@ -121,6 +132,8 @@ void process_start(int app_index)
121132 apps [app_index ].started = true;
122133 apps [app_index ].first_heartbeat = false;
123134 apps [app_index ].pid = pid ;
135+ // Record process start time from /proc/<pid>/stat
136+ apps [app_index ].start_time = get_process_start_time (pid );
124137 LOGI ("Process %s started (PID %d): %s" , apps [app_index ].name , apps [app_index ].pid , apps [app_index ].cmd );
125138 // Use heartbeat module to update heartbeat time
126139 heartbeat_update_time (app_index );
@@ -220,6 +233,7 @@ void process_kill(int app_index)
220233 apps [app_index ].started = false;
221234 apps [app_index ].first_heartbeat = false;
222235 apps [app_index ].pid = 0 ;
236+ apps [app_index ].start_time = 0 ;
223237 }
224238 else
225239 {
0 commit comments