--- a/libgksu/libgksu.c
+++ b/libgksu/libgksu.c
@@ -2906,9 +2906,13 @@
       /* Try hard to find the prompt; it may happen that we're
        * seeing sudo's lecture, or that some pam module is spitting
        * debugging stuff at the screen
+       *
+       * we wait up to 5sec for the prompt to appear, but we also
+       * break once the process_name changed
        */
-      for (counter = 0; counter < 50; counter++)
+      for (counter = 0; counter < 1000; counter++)
 	{
+	  char *procname;
 	  if (strncmp (buffer, "GNOME_SUDO_PASS", 15) == 0)
 	    break;
 
@@ -2921,7 +2925,11 @@
 	  if (context->debug)
 	    fprintf (stderr, "buffer: -%s-\n", buffer);
 
-	  usleep(1000);
+ 	  // we wait here  bit but break when the process name changes
+ 	  usleep(5000);
+ 	  procname = get_process_name (pid);
+ 	  if(!g_str_has_suffix(procname,"sudo"))
+ 	     break;
 	}
 
       if (context->debug)
