There seems to be an issue of ksh forwarding signals to recycled process
ids.
This was reported by a customer while running some script but looks like
the same can be reproduced with the following
steps.

1. ssh into a test machine.
2. Run some background job.
   for eg. sleep 10 &
   Note the process id.

3. In another terminal, create a process with the process id observed in
step 2.
   The attached C file can be used for this.
   Run as ./cpid process-id.

4. Forcibly disconnect the ssh connection in terminal 1 by
   entering ~.

We'll observe that the process created in step 3 is killed. Looks like ksh
forwards the SIGHUP to the recycled pid.

I've tested this in the 2011-02-08, 2012-08-01 and the latest 2014 version
on Solaris env.
This is also observed in Ubuntu 14(ksh2012-08-01).

I'm currently going through the job control code to figure out why this is
happening.
But as I'm quite new to the code, it might take me a while to figure
something out.

If someone has observed this earlier/investigated this, please let me know.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <wait.h>

int
main(int argc, char *argv[])
{
	pid_t	pid, rpid, opid;
	int	i, status, npid;

	if (argc != 2) {
		(void) fprintf(stderr, "Usage\n");
		exit(1);
	}

	rpid = atoi(argv[1]);

	opid = getpid();
	for (;;) {
		if ((pid = fork()) == 0) {
			(void) setpgrp();
			pause();
			_exit(0);
		}
		if (pid == rpid)
			break;

		(void) kill(pid, SIGKILL);
		(void) waitpid(pid, NULL, 0);

		if (opid < rpid && pid > rpid)
			(void) printf("Unable to create pid %d\n", rpid);
		opid = pid;
	}
	(void) printf("pid %d is ready\n", pid);

	i = waitpid(pid, &status, 0);
	(void) printf("waitpid return %d, status 0x%4.4x\n", i, status);

	return (0);
}
_______________________________________________
ast-developers mailing list
ast-developers@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-developers

Reply via email to