Github user trkurc commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1586#discussion_r109322091
  
    --- 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 --
    
    @PuspenduBanerjee - With this dependency, we'll have to put something in 
the LICENSE and NOTICE for the nifi-assembly, as it will pull this in and some 
transitive dependencies. It is ASLv2 license, but it appears it may pull in 
libffi which is a MIT style license 
(https://github.com/java-native-access/jna/tree/4.3.0/native/libffi). How they 
are building their native libs that are in their jars are not a bit challenging 
without diving in deeper than I'd like to. @phrocker may have seen a build 
process like that here: 
https://github.com/java-native-access/jna/tree/4.3.0/native and may be able to 
confirm that it is bundled in


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to