org.apache.hadoop.mapreduce.util
Class ProcfsBasedProcessTree

java.lang.Object
  extended by org.apache.hadoop.mapreduce.util.ProcessTree
      extended by org.apache.hadoop.mapreduce.util.ProcfsBasedProcessTree

@InterfaceAudience.Private
@InterfaceStability.Unstable
public class ProcfsBasedProcessTree
extends ProcessTree

A Proc file-system based ProcessTree. Works only on Linux.


Field Summary
static long JIFFY_LENGTH_IN_MILLIS
           
static long PAGE_SIZE
           
 
Fields inherited from class org.apache.hadoop.mapreduce.util.ProcessTree
DEFAULT_SLEEPTIME_BEFORE_SIGKILL, isSetsidAvailable
 
Constructor Summary
ProcfsBasedProcessTree(String pid)
           
ProcfsBasedProcessTree(String pid, boolean setsidUsed, long sigkillInterval)
           
ProcfsBasedProcessTree(String pid, boolean setsidUsed, long sigkillInterval, String procfsDir)
          Build a new process tree rooted at the pid.
 
Method Summary
static void assertAndDestroyProcessGroup(String pgrpId, long interval, boolean inBackground)
          Make sure that the given pid is a process group leader and then destroy the process group.
 void destroy()
          Destroy the process-tree.
 void destroy(boolean inBackground)
          Destroy the process-tree.
 long getCumulativeCpuTime()
          Get the CPU time in millisecond used by all the processes in the process-tree since the process-tree created
 long getCumulativeRssmem()
          Get the cumulative resident set size (rss) memory used by all the processes in the process-tree.
 long getCumulativeRssmem(int olderThanAge)
          Get the cumulative resident set size (rss) memory used by all the processes in the process-tree that are older than the passed in age.
 long getCumulativeVmem()
          Get the cumulative virtual memory used by all the processes in the process-tree.
 long getCumulativeVmem(int olderThanAge)
          Get the cumulative virtual memory used by all the processes in the process-tree that are older than the passed in age.
 String getProcessTreeDump()
          Get a dump of the process-tree.
 boolean isAlive()
          Is the root-process alive?
 boolean isAnyProcessInTreeAlive()
          Is any of the subprocesses in the process-tree alive?
static boolean isAvailable()
          Checks if the ProcfsBasedProcessTree is available on this system.
 void setSigKillInterval(long interval)
          Deprecated. Use ProcfsBasedProcessTree( String, boolean, long) instead
 String toString()
          Returns a string printing PIDs of process present in the ProcfsBasedProcessTree.
 void updateProcessTree()
          Update the process-tree with latest state.
 
Methods inherited from class org.apache.hadoop.mapreduce.util.ProcessTree
destroy, destroyProcess, destroyProcessGroup, isAlive, isProcessGroupAlive, killProcess, killProcessGroup, sigQuitProcess, sigQuitProcessGroup, terminateProcess, terminateProcessGroup
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PAGE_SIZE

public static final long PAGE_SIZE

JIFFY_LENGTH_IN_MILLIS

public static final long JIFFY_LENGTH_IN_MILLIS
Constructor Detail

ProcfsBasedProcessTree

public ProcfsBasedProcessTree(String pid)

ProcfsBasedProcessTree

public ProcfsBasedProcessTree(String pid,
                              boolean setsidUsed,
                              long sigkillInterval)

ProcfsBasedProcessTree

public ProcfsBasedProcessTree(String pid,
                              boolean setsidUsed,
                              long sigkillInterval,
                              String procfsDir)
Build a new process tree rooted at the pid. This method is provided mainly for testing purposes, where the root of the proc file system can be adjusted.

Parameters:
pid - root of the process tree
setsidUsed - true, if setsid was used for the root pid
sigkillInterval - how long to wait between a SIGTERM and SIGKILL when killing a process tree
procfsDir - the root of a proc file system - only used for testing.
Method Detail

setSigKillInterval

@Deprecated
public void setSigKillInterval(long interval)
Deprecated. Use ProcfsBasedProcessTree( String, boolean, long) instead

Sets SIGKILL interval

Parameters:
interval - The time to wait before sending SIGKILL after sending SIGTERM

isAvailable

public static boolean isAvailable()
Checks if the ProcfsBasedProcessTree is available on this system.

Returns:
true if ProcfsBasedProcessTree is available. False otherwise.

updateProcessTree

public void updateProcessTree()
Update the process-tree with latest state. If the root-process is not alive, tree will become empty.


isAlive

public boolean isAlive()
Is the root-process alive?

Returns:
true if the root-process is alive, false otherwise.

isAnyProcessInTreeAlive

public boolean isAnyProcessInTreeAlive()
Is any of the subprocesses in the process-tree alive?

Returns:
true if any of the processes in the process-tree is alive, false otherwise.

assertAndDestroyProcessGroup

public static void assertAndDestroyProcessGroup(String pgrpId,
                                                long interval,
                                                boolean inBackground)
                                         throws IOException
Make sure that the given pid is a process group leader and then destroy the process group.

Parameters:
pgrpId - Process group id of to-be-killed-processes
interval - The time to wait before sending SIGKILL after sending SIGTERM
inBackground - Process is to be killed in the back ground with a separate thread
Throws:
IOException

destroy

public void destroy()
Destroy the process-tree.


destroy

public void destroy(boolean inBackground)
Destroy the process-tree.

Parameters:
inBackground - Process is to be killed in the back ground with a separate thread

getProcessTreeDump

public String getProcessTreeDump()
Get a dump of the process-tree.

Returns:
a string concatenating the dump of information of all the processes in the process-tree

getCumulativeVmem

public long getCumulativeVmem()
Get the cumulative virtual memory used by all the processes in the process-tree.

Returns:
cumulative virtual memory used by the process-tree in bytes.

getCumulativeRssmem

public long getCumulativeRssmem()
Get the cumulative resident set size (rss) memory used by all the processes in the process-tree.

Returns:
cumulative rss memory used by the process-tree in bytes. return 0 if it cannot be calculated

getCumulativeVmem

public long getCumulativeVmem(int olderThanAge)
Get the cumulative virtual memory used by all the processes in the process-tree that are older than the passed in age.

Parameters:
olderThanAge - processes above this age are included in the memory addition
Returns:
cumulative virtual memory used by the process-tree in bytes, for processes older than this age.

getCumulativeRssmem

public long getCumulativeRssmem(int olderThanAge)
Get the cumulative resident set size (rss) memory used by all the processes in the process-tree that are older than the passed in age.

Parameters:
olderThanAge - processes above this age are included in the memory addition
Returns:
cumulative rss memory used by the process-tree in bytes, for processes older than this age. return 0 if it cannot be calculated

getCumulativeCpuTime

public long getCumulativeCpuTime()
Get the CPU time in millisecond used by all the processes in the process-tree since the process-tree created

Returns:
cumulative CPU time in millisecond since the process-tree created return 0 if it cannot be calculated

toString

public String toString()
Returns a string printing PIDs of process present in the ProcfsBasedProcessTree. Output format : [pid pid ..]

Overrides:
toString in class Object


Copyright © 2013 Apache Software Foundation. All Rights Reserved.