preap.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <ctype.h>
#include <string.h>
#include <signal.h>
#include <errno.h>
#include <libproc.h>
static volatile int interrupt;
static int Fflag;
static char *command;
static void
{
}
static int
{
char path[64];
int fd;
/*
* Attempt to open the usage file, and return the fd if we can
* confirm this is a regular file provided by /proc.
*/
fd = -1;
}
return (fd);
}
static int
{
int fd;
*perr = 0;
return (0);
}
/*
* If the read failed, the process may have gone away.
*/
}
return (-1);
}
/*
* Force the parent process (ppid) to wait for its child process (pid).
*/
static int
{
struct ps_prochandle *Pr;
int gret;
/*
* get the specified pid and the psinfo struct
*/
return (1);
}
return (1);
}
if (ppid == 1) {
"non-defunct ancestor is 'init'\n", command,
(int)pid);
return (1);
}
} else {
return (1);
}
return (1);
}
return (1);
}
"stopped and may reap status upon restart\n", command,
(int)pid);
return (1);
}
/*
* Pstop() will fail if the process to be stopped has become a zombie.
* This means that we can say with certainty that the child of this
* process has not changed parents (i.e. been reparented to init) once
* the Pstop() succeeds.
*/
return (1);
}
return (1);
}
return (0);
}
static void
{
if (WIFSIGNALED(wstat)) {
char buf[SIG2STR_MAX];
else
(void) printf(" (core dumped)");
} else {
}
(void) printf("\n");
}
int
{
int retc = 0;
int opt;
int errflg = 0;
command++;
else
switch (opt) {
case 'F': /* force grabbing (no O_EXCL) */
Fflag = PGRAB_FORCE;
break;
default:
errflg = 1;
break;
}
}
"its parent to wait(2) for it)\n");
exit(2);
}
/* catch signals from terminal */
int wstat, r;
if (r == 0)
}
retc++;
return (retc == 0 ? 0 : 1);
}