You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2017/04/02 21:34:41 UTC
[jira] [Commented] (NIFI-3586) Nifi is not returning PID in Windows
[ https://issues.apache.org/jira/browse/NIFI-3586?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15952859#comment-15952859 ]
ASF GitHub Bot commented on NIFI-3586:
--------------------------------------
Github user trkurc commented on a diff in the pull request:
https://github.com/apache/nifi/pull/1586#discussion_r109320687
--- Diff: nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/util/OSUtil.java ---
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nifi.bootstrap.util;
+
+import java.lang.reflect.Field;
+
+import org.slf4j.Logger;
+import com.sun.jna.Pointer;
+import com.sun.jna.platform.win32.Kernel32;
+import com.sun.jna.platform.win32.WinNT;
+
+/**
+ * OS specific utilities with generic method interfaces
+ */
+public final class OSUtil {
+
+ private static Long getUnicesPid(final Process process, final Logger logger) {
+ try {
+ final Class<?> procClass = process.getClass();
+ final Field pidField = procClass.getDeclaredField("pid");
+ pidField.setAccessible(true);
+ final Object pidObject = pidField.get(process);
+
+ logger.debug("PID Object = {}", pidObject);
+
+ if (pidObject instanceof Number) {
+ return ((Number) pidObject).longValue();
+ }
+ return null;
+ } catch (final IllegalAccessException | NoSuchFieldException nsfe) {
+ logger.debug("Could not find PID for child process due to {}", nsfe);
+ return null;
+ }
+ }
+
+ private static Long getWindowsProcessId(final Process process, final Logger logger) {
+ /* determine the pid on windows plattforms */
+ try {
+ Field f = process.getClass().getDeclaredField("handle");
+ f.setAccessible(true);
+ long handl = f.getLong(process);
+
+ Kernel32 kernel = Kernel32.INSTANCE;
+ WinNT.HANDLE handle = new WinNT.HANDLE();
+ handle.setPointer(Pointer.createConstant(handl));
+ int ret = kernel.GetProcessId(handle);
+ logger.debug("Detected pid: {}", ret);
+ return Long.valueOf(ret);
+ } catch (final IllegalAccessException | NoSuchFieldException nsfe) {
+ logger.debug("Could not find PID for child process due to {}", nsfe);
+ }
+ return null;
+ }
+
+ public static Long getProcessId(final Process process, final Logger logger) {
--- End diff --
I know it wasn't there before when this was a private method before, but I'd LOVE to see a javadoc comment to describe the contract for this method. I think returning null is a bit counter-intuitive
> Nifi is not returning PID in Windows
> ------------------------------------
>
> Key: NIFI-3586
> URL: https://issues.apache.org/jira/browse/NIFI-3586
> Project: Apache NiFi
> Issue Type: Bug
> Components: Core Framework
> Affects Versions: 1.0.0, 0.5.0, 0.6.0, 0.7.0, 1.2.0, 1.1.1, 1.0.1
> Environment: Java <=8, Windows
> Reporter: Puspendu Banerjee
> Priority: Minor
>
> Nifi PID is unavailable during startup under Windows
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)