HOSTINFO_PROCESS_QUERY_UNKNOWN // Process existence cannot be determined
} HostinfoProcessQuery;
+typedef struct HostinfoProcessSnapshot HostinfoProcessSnapshot;
+
+HostinfoProcessSnapshot *Hostinfo_AcquireProcessSnapshot(void);
+void Hostinfo_ReleaseProcessSnapshot(HostinfoProcessSnapshot *s);
+
+HostinfoProcessQuery Hostinfo_QueryProcessSnapshot(HostinfoProcessSnapshot *s,
+ int pid);
+
HostinfoProcessQuery Hostinfo_QueryProcessExistence(int pid);
/* This macro defines the current version of the structured header. */
/*********************************************************
- * Copyright (C) 1998-2019 VMware, Inc. All rights reserved.
+ * Copyright (C) 1998-2022 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
return detailedData;
}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * Hostinfo_QueryProcessExistence --
+ *
+ * Determine if a PID is "alive" or "dead". Failing to be able to
+ * do this perfectly, do not make any assumption - say the answer
+ * is unknown.
+ *
+ * Results:
+ * HOSTINFO_PROCESS_QUERY_ALIVE Process is alive
+ * HOSTINFO_PROCESS_QUERY_DEAD Process is dead
+ * HOSTINFO_PROCESS_QUERY_UNKNOWN Don't know
+ *
+ * Side effects:
+ * None
+ *
+ *----------------------------------------------------------------------
+ */
+
+HostinfoProcessQuery
+Hostinfo_QueryProcessExistence(int pid) // IN:
+{
+ HostinfoProcessQuery ret;
+ HostinfoProcessSnapshot *s = Hostinfo_AcquireProcessSnapshot();
+
+ if (s == NULL) {
+ return HOSTINFO_PROCESS_QUERY_UNKNOWN;
+ }
+
+ ret = Hostinfo_QueryProcessSnapshot(s, pid);
+
+ Hostinfo_ReleaseProcessSnapshot(s);
+
+ return ret;
+}
+
/*
*----------------------------------------------------------------------
*
- * Hostinfo_QueryProcessExistence --
+ * Hostinfo_AcquireProcessSnapshot --
*
- * Determine if a PID is "alive" or "dead". Failing to be able to
- * do this perfectly, do not make any assumption - say the answer
- * is unknown.
+ * Acquire a snapshot of the process table. On POSIXen, this is
+ * a NOP.
+ *
+ * Results:
+ * !NULL - A process snapshot pointer.
+ *
+ * Side effects:
+ * None
+ *
+ *----------------------------------------------------------------------
+ */
+
+struct HostinfoProcessSnapshot {
+ int dummy;
+};
+
+static HostinfoProcessSnapshot hostinfoProcessSnapshot = { 0 };
+
+HostinfoProcessSnapshot *
+Hostinfo_AcquireProcessSnapshot(void)
+{
+ return &hostinfoProcessSnapshot;
+}
+
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * Hostinfo_ReleaseProcessSnapshot --
+ *
+ * Release a snapshot of the process table. On POSIXen, this is
+ * a NOP.
+ *
+ * Results:
+ * None
+ *
+ * Side effects:
+ * None
+ *
+ *----------------------------------------------------------------------
+ */
+
+void
+Hostinfo_ReleaseProcessSnapshot(HostinfoProcessSnapshot *s) // IN/OPT:
+{
+ if (s != NULL) {
+ VERIFY(s == &hostinfoProcessSnapshot);
+ }
+}
+
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * Hostinfo_QueryProcessSnapshot --
+ *
+ * Determine if a PID is "alive" or "dead" within the specified
+ * process snapshot. Failing to be able to do this perfectly,
+ * do not make any assumption - say the answer is unknown.
*
* Results:
* HOSTINFO_PROCESS_QUERY_ALIVE Process is alive
*/
HostinfoProcessQuery
-Hostinfo_QueryProcessExistence(int pid) // IN:
+Hostinfo_QueryProcessSnapshot(HostinfoProcessSnapshot *s, // IN:
+ int pid) // IN:
{
HostinfoProcessQuery ret;
- int err = (kill(pid, 0) == -1) ? errno : 0;
- switch (err) {
+ ASSERT(s != NULL);
+
+ switch ((kill(pid, 0) == -1) ? errno : 0) {
case 0:
case EPERM:
ret = HOSTINFO_PROCESS_QUERY_ALIVE;
return ret;
}
+