Index: trunk/src/kWorker/kWorker.c
===================================================================
--- trunk/src/kWorker/kWorker.c	(revision 3049)
+++ trunk/src/kWorker/kWorker.c	(revision 3051)
@@ -11124,9 +11124,42 @@
         else if (strcmp(argv[i], "--test") == 0)
             return kwTestRun(argc - i - 1, &argv[i + 1]);
+        else if (strcmp(argv[i], "--priority") == 0)
+        {
+            i++;
+            if (i < argc)
+            {
+                char *pszEnd = NULL;
+                unsigned long uValue = strtoul(argv[i], &pszEnd, 16);
+                if (   *argv[i]
+                    && pszEnd != NULL
+                    && *pszEnd == '\0'
+                    && uValue >= 1
+                    && uValue <= 5)
+                {
+                    DWORD dwClass, dwPriority;
+                    switch (uValue)
+                    {
+                        case 1: dwClass = IDLE_PRIORITY_CLASS;         dwPriority = THREAD_PRIORITY_IDLE; break;
+                        case 2: dwClass = BELOW_NORMAL_PRIORITY_CLASS; dwPriority = THREAD_PRIORITY_BELOW_NORMAL; break;
+                        case 3: dwClass = NORMAL_PRIORITY_CLASS;       dwPriority = THREAD_PRIORITY_NORMAL; break;
+                        case 4: dwClass = HIGH_PRIORITY_CLASS;         dwPriority = 0xffffffff; break;
+                        case 5: dwClass = REALTIME_PRIORITY_CLASS;     dwPriority = 0xffffffff; break;
+                    }
+                    SetPriorityClass(GetCurrentProcess(), dwClass);
+                    if (dwPriority != 0xffffffff)
+                        SetThreadPriority(GetCurrentThread(), dwPriority);
+                }
+                else
+                    return kwErrPrintfRc(2, "Invalid --priority argument: %s\n", argv[i]);
+            }
+            else
+                return kwErrPrintfRc(2, "--priority takes an argument!\n");
+
+        }
         else if (   strcmp(argv[i], "--help") == 0
                  || strcmp(argv[i], "-h") == 0
                  || strcmp(argv[i], "-?") == 0)
         {
-            printf("usage: kWorker [--volatile dir] --pipe <pipe-handle>\n"
+            printf("usage: kWorker [--volatile dir] [--priority <1-5>] --pipe <pipe-handle>\n"
                    "usage: kWorker <--help|-h>\n"
                    "usage: kWorker <--version|-V>\n"
Index: trunk/src/kmk/kmkbuiltin/kSubmit.c
===================================================================
--- trunk/src/kmk/kmkbuiltin/kSubmit.c	(revision 3049)
+++ trunk/src/kmk/kmkbuiltin/kSubmit.c	(revision 3051)
@@ -383,11 +383,24 @@
                 {
                     char        szHandleArg[32];
-                    const char *apszArgs[6] =
+                    extern int process_priority; /* main.c */
+                    char        szPriorityArg[32];
+                    const char *apszArgs[10];
+                    int         cArgs = 0;
+                    apszArgs[cArgs++] = szExecutable;
+                    apszArgs[cArgs++] = "--pipe";
+                    _snprintf(szHandleArg, sizeof(szHandleArg), "%p", hWorkerPipe);
+                    apszArgs[cArgs++] = szHandleArg;
+                    if (pVarVolatile)
                     {
-                        szExecutable, "--pipe", szHandleArg,
-                        pVarVolatile ? "--volatile" : NULL, pVarVolatile ? pVarVolatile->value : NULL,
-                        NULL
-                    };
-                    _snprintf(szHandleArg, sizeof(szHandleArg), "%p", hWorkerPipe);
+                        apszArgs[cArgs++] = "--volatile";
+                        apszArgs[cArgs++] = pVarVolatile->value;
+                    }
+                    if (process_priority != 0)
+                    {
+                        apszArgs[cArgs++] = "--priority";
+                        _snprintf(szPriorityArg, sizeof(szPriorityArg), "%u", process_priority);
+                        apszArgs[cArgs++] = szPriorityArg;
+                    }
+                    apszArgs[cArgs] = NULL;
 
                     /*
Index: trunk/src/kmk/main.c
===================================================================
--- trunk/src/kmk/main.c	(revision 3049)
+++ trunk/src/kmk/main.c	(revision 3051)
@@ -863,8 +863,9 @@
 {
 # ifdef WINDOWS32
-  DWORD dwPriority;
+  DWORD dwClass, dwPriority;
+
   if (process_affinity)
     if (!SetProcessAffinityMask (GetCurrentProcess (), process_affinity))
-      fprintf (stderr, "warning: SetPriorityClass (,%#x) failed with last error %d\n",
+      fprintf (stderr, "warning: SetProcessAffinityMask (,%#x) failed with last error %d\n",
                process_affinity, GetLastError ());
 
@@ -872,13 +873,17 @@
     {
       case 0:     return;
-      case 1:     dwPriority = IDLE_PRIORITY_CLASS; break;
-      case 2:     dwPriority = BELOW_NORMAL_PRIORITY_CLASS; break;
-      case 3:     dwPriority = NORMAL_PRIORITY_CLASS; break;
-      case 4:     dwPriority = HIGH_PRIORITY_CLASS; break;
-      case 5:     dwPriority = REALTIME_PRIORITY_CLASS; break;
+      case 1:     dwClass = IDLE_PRIORITY_CLASS;         dwPriority = THREAD_PRIORITY_IDLE; break;
+      case 2:     dwClass = BELOW_NORMAL_PRIORITY_CLASS; dwPriority = THREAD_PRIORITY_BELOW_NORMAL; break;
+      case 3:     dwClass = NORMAL_PRIORITY_CLASS;       dwPriority = THREAD_PRIORITY_NORMAL; break;
+      case 4:     dwClass = HIGH_PRIORITY_CLASS;         dwPriority = 0xffffffff; break;
+      case 5:     dwClass = REALTIME_PRIORITY_CLASS;     dwPriority = 0xffffffff; break;
       default:    fatal (NILF, _("invalid priority %d\n"), process_priority);
     }
-  if (!SetPriorityClass (GetCurrentProcess (), dwPriority))
+  if (!SetPriorityClass (GetCurrentProcess (), dwClass))
     fprintf (stderr, "warning: SetPriorityClass (,%#x) failed with last error %d\n",
+             dwClass, GetLastError ());
+  if (dwPriority != 0xffffffff
+      && !SetThreadPriority (GetCurrentThread (), dwPriority))
+    fprintf (stderr, "warning: SetThreadPriority (,%#x) failed with last error %d\n",
              dwPriority, GetLastError ());
 
Index: trunk/src/kmk/w32/subproc/sub_proc.c
===================================================================
--- trunk/src/kmk/w32/subproc/sub_proc.c	(revision 3049)
+++ trunk/src/kmk/w32/subproc/sub_proc.c	(revision 3051)
@@ -548,4 +548,5 @@
 #ifdef KMK
         size_t exec_path_len;
+	extern int process_priority;
 
 	assert (pproc->enmType == kRegular);
@@ -716,4 +717,12 @@
 		else if (argv[0])
 			kmk_cache_exec_image(argv[0]);
+
+		switch (process_priority) {
+		case 1: flags |= CREATE_SUSPENDED | IDLE_PRIORITY_CLASS; break;
+		case 2: flags |= CREATE_SUSPENDED | BELOW_NORMAL_PRIORITY_CLASS; break;
+		case 3: flags |= CREATE_SUSPENDED | NORMAL_PRIORITY_CLASS; break;
+		case 4: flags |= CREATE_SUSPENDED | HIGH_PRIORITY_CLASS; break;
+		case 5: flags |= CREATE_SUSPENDED | REALTIME_PRIORITY_CLASS; break;
+		}
 #endif
 		if (CreateProcess(
@@ -741,4 +750,14 @@
 			return(-1);
 		}
+#ifdef KMK
+		switch (process_priority) {
+		case 1: SetThreadPriority(procInfo.hThread, THREAD_PRIORITY_IDLE); break;
+		case 2: SetThreadPriority(procInfo.hThread, THREAD_PRIORITY_BELOW_NORMAL); break;
+		case 3: SetThreadPriority(procInfo.hThread, THREAD_PRIORITY_NORMAL); break;
+		case 4: SetThreadPriority(procInfo.hThread, THREAD_PRIORITY_HIGHEST); break;
+		case 5: SetThreadPriority(procInfo.hThread, THREAD_PRIORITY_TIME_CRITICAL); break;
+		}
+		ResumeThread(procInfo.hThread);
+#endif
 	}
 
