1 /** 2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 * SPDX-License-Identifier: Apache-2.0. 4 */ 5 6 package software.amazon.awssdk.crt; 7 8 import static software.amazon.awssdk.crt.CRT.awsErrorString; 9 import static software.amazon.awssdk.crt.CRT.awsLastError; 10 11 /** 12 * Encapsulates Process information and manipulation of process level operations. 13 */ 14 public class Process { 15 /** 16 * Gets the process id of the running process. 17 * @return process id. 18 */ getPid()19 public static int getPid() { 20 return processGetPid(); 21 } 22 23 /** 24 * Gets the soft limit for IO handles for this process (max fds in unix terminology) 25 * 26 * @return soft limit for IO handles. 27 */ getMaxIOHandlesSoftLimit()28 public static long getMaxIOHandlesSoftLimit() { 29 return processGetMaxIOHandlesSoftLimit(); 30 } 31 32 /** 33 * Gets the hard limit for IO handles for this process (max fds in unix terminology). This 34 * value cannot be altered without root permissions. 35 * 36 * @return hard limit for IO handles. 37 */ getMaxIOHandlesHardLimit()38 public static long getMaxIOHandlesHardLimit() { 39 return processGetMaxIOHandlesHardLimit(); 40 } 41 42 /** 43 * Sets the soft limit for IO handles for this process (max fds in unix terminology). maxHandles may not exceed the 44 * return value of getMaxIOHandlesHardLimit(). In addition, avoid calling this function unless you've checked 45 * getMaxIOHandlesSoftLimit() is actually less than getMaxIOHandlesHardLimit() since this function will always 46 * fail on some platforms (such as windows) where there are no practical limits in the first place. 47 * 48 * @param maxHandles new soft limit for this process. 49 * 50 * @throws CrtRuntimeException if the operation fails due to illegal arguments or the opereration is unsupported on 51 * the current platform. 52 */ setMaxIOHandlesSoftLimit(long maxHandles)53 public static void setMaxIOHandlesSoftLimit(long maxHandles) { 54 if (!processSetMaxIOHandlesSoftLimit(maxHandles)) { 55 int lastError = awsLastError(); 56 throw new CrtRuntimeException(lastError); 57 } 58 } 59 processGetPid()60 private static native int processGetPid(); processGetMaxIOHandlesSoftLimit()61 private static native long processGetMaxIOHandlesSoftLimit(); processGetMaxIOHandlesHardLimit()62 private static native long processGetMaxIOHandlesHardLimit(); processSetMaxIOHandlesSoftLimit(long maxHandles)63 private static native boolean processSetMaxIOHandlesSoftLimit(long maxHandles); 64 } 65