--- fcgi_pm.c.orig	2008-04-04 09:34:20.000000000 +0200
+++ fcgi_pm.c	2008-04-04 09:37:58.000000000 +0200
@@ -128,8 +128,26 @@
         int numChildren = (s->directive == APP_CLASS_DYNAMIC)
             ? dynamicMaxClassProcs
             : s->numProcesses;
+
+        /* Send TERM to all processes */
+        for (i = 0; i < numChildren; i++, proc++) 
+        {
+            if (proc->state == FCGI_RUNNING_STATE) 
+            {
+                fcgi_kill(proc, SIGTERM);
+            }
+        }
         
+        s = s->next;
+    }
+ 
 #ifndef WIN32
+    /* sleep two seconds to let the children terminate themselves */
+    sleep(2);
+    s = fcgi_servers;
+    
+    while (s) 
+    {
         if (s->socket_path != NULL && s->directive != APP_CLASS_EXTERNAL) 
         {
             /* Remove the socket file */
@@ -140,19 +158,9 @@
                     (s->directive == APP_CLASS_DYNAMIC) ? " (dynamic)" : "", s->fs_path);
             }
         }
-#endif
-
-        /* Send TERM to all processes */
-        for (i = 0; i < numChildren; i++, proc++) 
-        {
-            if (proc->state == FCGI_RUNNING_STATE) 
-            {
-                fcgi_kill(proc, SIGTERM);
-            }
-        }
-        
         s = s->next;
     }
+#endif
 
 #if defined(WIN32) && (WIN32_SHUTDOWN_GRACEFUL_WAIT > 0)