File:  [Research Unix] / researchv9 / jtools / src / cmd / hang.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:21:59 2018 UTC (8 years, 1 month ago) by root
Branches: belllabs, MAIN
CVS tags: researchv9-SUN3_old, researchv9-SUN3, HEAD
researchv9-SUN3(old)

#include <stdio.h>
#include <signal.h>
#include <sys/ptrace.h>
#include <sys/wait.h>

/*
 * bsd semi-equivalent of Ninth Edition hang
 *
 * D. A. Kapilow		12/18/87
 */

main(argc,argv)
int argc; char **argv;
{
	int pid, wpid;
	union wait status;

	if (argc <= 1) {
		fprintf(stderr,"Usage: %s cmd [args...]\n",*argv);
		exit(1);
	}
	if ((pid = fork()) == 0) {
		ptrace(PTRACE_TRACEME, 0, 0, 0, 0);
		execvp(argv[1], argv+1);
		perror(argv[1]);
		exit(1);
	}
	if (pid < 0) {
		fprintf(stderr,"%s: can't fork\n",*argv);
		exit(1);
	}
	while ((wpid = wait(&status)) != pid)
		;
	if (!WIFSTOPPED(status) || status.w_stopsig != SIGTRAP) {
		fprintf(stderr,"%s: child died\n",*argv);
		exit(1);
	}
	kill(pid, SIGSTOP);
	ptrace(PTRACE_DETACH, pid, (int *)1, 0, 0);
	fprintf(stderr, "%d %s\n", pid, argv[1]);
	while ((wpid = wait(&status)) != pid)
		if (wpid < 0)
			exit(1);
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.