diff --git a/src/slurmd/slurmstepd/mgr.c b/src/slurmd/slurmstepd/mgr.c
index f0de161542d83b19514c8b01fd9bf67a543f49c4..4e43e440ca35a6be133b4b240e3575e82e979798 100644
--- a/src/slurmd/slurmstepd/mgr.c
+++ b/src/slurmd/slurmstepd/mgr.c
@@ -1052,7 +1052,7 @@ fail2:
 	 * terminated before the switch window can be released by
 	 * interconnect_postfini().
 	 */
-	step_terminate_monitor_start(job->jobid, job->stepid);
+	step_terminate_monitor_start(job->jobid, job->stepid, job->uid);
 	if (job->cont_id != 0) {
 		slurm_container_signal(job->cont_id, SIGKILL);
 		slurm_container_wait(job->cont_id);
diff --git a/src/slurmd/slurmstepd/req.c b/src/slurmd/slurmstepd/req.c
index 4fb25d373dc93c340f3381d514c0920e29826406..926df60d770f706a7891a74c8c4f963a52a3d9a0 100644
--- a/src/slurmd/slurmstepd/req.c
+++ b/src/slurmd/slurmstepd/req.c
@@ -903,7 +903,7 @@ _handle_terminate(int fd, stepd_step_rec_t *job, uid_t uid)
 
 	debug("_handle_terminate for step=%u.%u uid=%d",
 	      job->jobid, job->stepid, uid);
-	step_terminate_monitor_start(job->jobid, job->stepid);
+	step_terminate_monitor_start(job->jobid, job->stepid, job->uid);
 
 	if (uid != job->uid && !_slurm_authorized_user(uid)) {
 		debug("terminate req from uid %ld for job %u.%u "
diff --git a/src/slurmd/slurmstepd/step_terminate_monitor.c b/src/slurmd/slurmstepd/step_terminate_monitor.c
index 93f5d56ab348094f0a69706cb49523050ac5b3b8..2c5bf5f2012f6c74befec8d4b4d22f1ba017650c 100644
--- a/src/slurmd/slurmstepd/step_terminate_monitor.c
+++ b/src/slurmd/slurmstepd/step_terminate_monitor.c
@@ -58,11 +58,12 @@ static uint16_t timeout;
 static char *program_name;
 static uint32_t recorded_jobid = NO_VAL;
 static uint32_t recorded_stepid = NO_VAL;
+static uid_t    recorded_uid = 0;
 
 static void *_monitor(void *);
 static int _call_external_program(void);
 
-void step_terminate_monitor_start(uint32_t jobid, uint32_t stepid)
+void step_terminate_monitor_start(uint32_t jobid, uint32_t stepid, uid_t uid)
 {
 	slurm_ctl_conf_t *conf;
 	pthread_attr_t attr;
@@ -91,6 +92,7 @@ void step_terminate_monitor_start(uint32_t jobid, uint32_t stepid)
 	running_flag = 1;
 	recorded_jobid = jobid;
 	recorded_stepid = stepid;
+	recorded_uid = uid;
 
 	pthread_mutex_unlock(&lock);
 
@@ -201,7 +203,7 @@ static int _call_external_program(void)
 		exit(127);
 	}
 
-	if (container_g_add_pid(recorded_jobid, cpid, getuid()) !=
+	if (container_g_add_pid(recorded_jobid, cpid, recorded_uid) !=
 	    SLURM_SUCCESS)
 		error("container_g_add_pid(%u): %m", recorded_jobid);
 
diff --git a/src/slurmd/slurmstepd/step_terminate_monitor.h b/src/slurmd/slurmstepd/step_terminate_monitor.h
index d5b56746a346fac4d2d65c7a50b80130926751b4..984481e21a0edf4f6d62a12e6c7931f82b46a5c6 100644
--- a/src/slurmd/slurmstepd/step_terminate_monitor.h
+++ b/src/slurmd/slurmstepd/step_terminate_monitor.h
@@ -26,6 +26,9 @@
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
 \*****************************************************************************/
 
+#ifndef _SLURMD_TERM_MONITOR_H
+#define _SLURMD_TERM_MONITOR_H
+
 /*
  * Start a monitor pthread that will wait for a period of time,
  * as defined in the slurm.conf variable UnkillableStepTimeout,
@@ -42,10 +45,12 @@
  * If step_terminate_monitor_stop() is called before the time runs
  * out, the external program will not be called.
  */
-void step_terminate_monitor_start(uint32_t jobid, uint32_t stepid);
+void step_terminate_monitor_start(uint32_t jobid, uint32_t stepid, uid_t uid);
 
 /*
  * Stop the timer in the step terminate monitor pthread, and kill
  * said pthread.
  */
 void step_terminate_monitor_stop(void);
+
+#endif /* !_SLURMD_TERM_MONITOR_H */