Index: /branches/eam_branches/ipp-20110906/Ohana/src/opihi/include/pantasks.h
===================================================================
--- /branches/eam_branches/ipp-20110906/Ohana/src/opihi/include/pantasks.h	(revision 32583)
+++ /branches/eam_branches/ipp-20110906/Ohana/src/opihi/include/pantasks.h	(revision 32584)
@@ -115,4 +115,5 @@
 
   int active;
+  int priority;
 
 } Task;
@@ -159,4 +160,5 @@
 
   JobMode     mode;			/* local or controller? */
+  int     priority;
   char   *realhost;
 
Index: /branches/eam_branches/ipp-20110906/Ohana/src/opihi/include/pcontrol.h
===================================================================
--- /branches/eam_branches/ipp-20110906/Ohana/src/opihi/include/pcontrol.h	(revision 32583)
+++ /branches/eam_branches/ipp-20110906/Ohana/src/opihi/include/pcontrol.h	(revision 32584)
@@ -119,4 +119,5 @@
   int          exit_status;
   int          Reset;
+  int          priority;
   JobMode      mode;
   JobStat      state;
@@ -313,5 +314,5 @@
 Job   *PullJobByID (IDtype JobID, int *StackID);
 Job   *PullJobFromStackByID (int StackID, int ID);
-IDtype AddJob (char *hostname, JobMode mode, int timeout, int argc, char **argv, int Nxhosts, char **xhosts);
+IDtype AddJob (char *hostname, JobMode mode, int timeout, int priority, int argc, char **argv, int Nxhosts, char **xhosts);
 void   DelJob (Job *job);
 Host  *UnlinkJobAndHost (Job *job);
Index: /branches/eam_branches/ipp-20110906/Ohana/src/opihi/pantasks/ControllerOps.c
===================================================================
--- /branches/eam_branches/ipp-20110906/Ohana/src/opihi/pantasks/ControllerOps.c	(revision 32583)
+++ /branches/eam_branches/ipp-20110906/Ohana/src/opihi/pantasks/ControllerOps.c	(revision 32584)
@@ -258,4 +258,10 @@
       sprintf (cmd, "job -host %s", job[0].task[0].host);
     }
+  }
+  
+  if (job[0].priority) {
+    char tmp[64];
+    snprintf (tmp, 64, " -nice %d", job[0].priority);
+    strcat (cmd, tmp);
   }
 
Index: /branches/eam_branches/ipp-20110906/Ohana/src/opihi/pantasks/JobOps.c
===================================================================
--- /branches/eam_branches/ipp-20110906/Ohana/src/opihi/pantasks/JobOps.c	(revision 32583)
+++ /branches/eam_branches/ipp-20110906/Ohana/src/opihi/pantasks/JobOps.c	(revision 32584)
@@ -107,4 +107,5 @@
     job[0].mode = JOB_CONTROLLER;
   }
+  job[0].priority = task[0].priority;
 
   /* we need our own copy of task[0].argv argc is the number of valid args, like the usual command line.  we
Index: /branches/eam_branches/ipp-20110906/Ohana/src/opihi/pantasks/LocalJob.c
===================================================================
--- /branches/eam_branches/ipp-20110906/Ohana/src/opihi/pantasks/LocalJob.c	(revision 32583)
+++ /branches/eam_branches/ipp-20110906/Ohana/src/opihi/pantasks/LocalJob.c	(revision 32584)
@@ -161,4 +161,14 @@
   if (VerboseMode()) gprint (GP_ERR, "local job launched\n");
 
+  /* set nice level for the child process -- maybe I should not exit here... */
+  if (job[0].priority) {
+      status = setpriority (PRIO_PROCESS, pid, job[0].priority);
+      if (status == -1) {
+	  gprint (GP_ERR, "error setting priority\n");
+	  perror ("setpriority: ");
+	  exit (2);
+      }
+  }
+
   /* close the other ends of the pipes */
   close (stdout_fd[1]); stdout_fd[1] = 0;
Index: /branches/eam_branches/ipp-20110906/Ohana/src/opihi/pantasks/TaskOps.c
===================================================================
--- /branches/eam_branches/ipp-20110906/Ohana/src/opihi/pantasks/TaskOps.c	(revision 32583)
+++ /branches/eam_branches/ipp-20110906/Ohana/src/opihi/pantasks/TaskOps.c	(revision 32584)
@@ -487,4 +487,5 @@
 
   NewTask[0].active = TRUE;
+  NewTask[0].priority = 0;
   return (NewTask);
 }
Index: /branches/eam_branches/ipp-20110906/Ohana/src/opihi/pantasks/task_nice.c
===================================================================
--- /branches/eam_branches/ipp-20110906/Ohana/src/opihi/pantasks/task_nice.c	(revision 32584)
+++ /branches/eam_branches/ipp-20110906/Ohana/src/opihi/pantasks/task_nice.c	(revision 32584)
@@ -0,0 +1,34 @@
+# include "pantasks.h"
+
+int task_nice (int argc, char **argv) {
+
+  char *endptr = NULL;
+  int priority;
+  Task *task;
+
+  if (argc != 3) {
+    gprint (GP_ERR, "USAGE: nice (priority)\n");
+    return (FALSE);
+  }
+
+  JobTaskLock();
+  task = GetNewTask ();
+  if (task == NULL) {
+    gprint (GP_ERR, "ERROR: not defining or running a task\n");
+    JobTaskUnlock();
+    return (FALSE);
+  }
+
+  priority = strtol (argv[1], &endptr, 10);
+  if (*endptr) goto fail;
+  if (priority < 0) goto fail;
+  if (priority > 20) goto fail;
+
+  task[0].priority = priority;
+  JobTaskUnlock();
+  return (TRUE);
+
+fail:
+    gprint (GP_ERR, "ERROR: nice (priority) -- priority must be an integer 0 to 20\n");
+    return (FALSE);
+}
Index: /branches/eam_branches/ipp-20110906/Ohana/src/opihi/pclient/job.c
===================================================================
--- /branches/eam_branches/ipp-20110906/Ohana/src/opihi/pclient/job.c	(revision 32583)
+++ /branches/eam_branches/ipp-20110906/Ohana/src/opihi/pclient/job.c	(revision 32584)
@@ -3,6 +3,13 @@
 int job (int argc, char **argv) {
 
-  int i, pid, status;
+  int i, pid, status, priority;
   char **targv;
+
+  priority = 0;
+  if ((N = get_argument (argc, argv, "-nice"))) {
+    remove_argument (N, &argc, argv);
+    priority = atoi (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
 
   if (argc < 2) {
@@ -54,4 +61,14 @@
   }
 
+  /* set nice level for the child process */
+  if (priority) {
+      status = setpriority (PRIO_PROCESS, pid, priority);
+      if (status == -1) {
+	  gprint (GP_ERR, "error setting priority\n");
+	  perror ("setpriority: ");
+	  exit (2);
+      }
+  }
+
   /* free temporary arg list */
   for (i = 0; i < argc - 1; i++) {
Index: /branches/eam_branches/ipp-20110906/Ohana/src/opihi/pcontrol/JobOps.c
===================================================================
--- /branches/eam_branches/ipp-20110906/Ohana/src/opihi/pcontrol/JobOps.c	(revision 32583)
+++ /branches/eam_branches/ipp-20110906/Ohana/src/opihi/pcontrol/JobOps.c	(revision 32584)
@@ -195,5 +195,5 @@
 }
 
-IDtype AddJob (char *hostname, JobMode mode, int timeout, int argc, char **argv, int Nxhosts, char **xhosts) {
+IDtype AddJob (char *hostname, JobMode mode, int timeout, int priority, int argc, char **argv, int Nxhosts, char **xhosts) {
 
   int JobID;
@@ -220,4 +220,5 @@
 
   job[0].mode     = mode;
+  job[0].priority = priority;
 
   job[0].state = 0;
Index: /branches/eam_branches/ipp-20110906/Ohana/src/opihi/pcontrol/StartJob.c
===================================================================
--- /branches/eam_branches/ipp-20110906/Ohana/src/opihi/pcontrol/StartJob.c	(revision 32583)
+++ /branches/eam_branches/ipp-20110906/Ohana/src/opihi/pcontrol/StartJob.c	(revision 32584)
@@ -25,4 +25,9 @@
   bzero (line, Nline);
   strcpy (line, "job");
+  if (job[0].priority) {
+    char tmp[64];
+    snprintf (tmp, 64, " -nice %d", job[0].priority);
+    strcat (line, tmp);
+  }
   for (i = 0; i < job[0].argc; i++) {
     strcat (line, " ");
Index: /branches/eam_branches/ipp-20110906/Ohana/src/opihi/pcontrol/job.c
===================================================================
--- /branches/eam_branches/ipp-20110906/Ohana/src/opihi/pcontrol/job.c	(revision 32583)
+++ /branches/eam_branches/ipp-20110906/Ohana/src/opihi/pcontrol/job.c	(revision 32584)
@@ -5,5 +5,5 @@
   char *Host = NULL;
   char **targv = NULL;
-  int i, N, Mode, targc, Timeout;
+  int i, N, Mode, targc, Timeout, priority;
   IDtype JobID;
   char **xhosts = NULL;
@@ -43,4 +43,11 @@
   }
 
+  priority = 0;
+  if ((N = get_argument (argc, argv, "-nice"))) {
+    remove_argument (N, &argc, argv);
+    priority = atoi (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+
   xhosts = NULL;
   Nxhosts = 0;
@@ -72,5 +79,5 @@
 
   // a JobID < 0 mean the job was not accepted
-  JobID = AddJob (Host, Mode, Timeout, targc, targv, Nxhosts, xhosts);
+  JobID = AddJob (Host, Mode, Timeout, priority, targc, targv, Nxhosts, xhosts);
   gprint (GP_LOG, "JobID: %d\n", (int) JobID);
   return (TRUE);
