001    // This file is part of the program FRYSK.
002    //
003    // Copyright 2005, 2007, 2008, Red Hat Inc.
004    //
005    // FRYSK is free software; you can redistribute it and/or modify it
006    // under the terms of the GNU General Public License as published by
007    // the Free Software Foundation; version 2 of the License.
008    //
009    // FRYSK is distributed in the hope that it will be useful, but
010    // WITHOUT ANY WARRANTY; without even the implied warranty of
011    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012    // General Public License for more details.
013    // 
014    // You should have received a copy of the GNU General Public License
015    // along with FRYSK; if not, write to the Free Software Foundation,
016    // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
017    // 
018    // In addition, as a special exception, Red Hat, Inc. gives You the
019    // additional right to link the code of FRYSK with code not covered
020    // under the GNU General Public License ("Non-GPL Code") and to
021    // distribute linked combinations including the two, subject to the
022    // limitations in this paragraph. Non-GPL Code permitted under this
023    // exception must only link to the code of FRYSK through those well
024    // defined interfaces identified in the file named EXCEPTION found in
025    // the source code files (the "Approved Interfaces"). The files of
026    // Non-GPL Code may instantiate templates or use macros or inline
027    // functions from the Approved Interfaces without causing the
028    // resulting work to be covered by the GNU General Public
029    // License. Only Red Hat, Inc. may make changes or additions to the
030    // list of Approved Interfaces. You must obey the GNU General Public
031    // License in all respects for all of the FRYSK code and other code
032    // used in conjunction with FRYSK except the Non-GPL Code covered by
033    // this exception. If you modify this file, you may extend this
034    // exception to your version of the file, but you are not obligated to
035    // do so. If you do not wish to provide this exception without
036    // modification, you must delete this exception statement from your
037    // version and license this file solely under the GPL without
038    // exception.
039    
040    package frysk.sys.proc;
041    
042    import frysk.sys.ProcessIdentifier;
043    import frysk.rsl.Log;
044    
045    /**
046     * The contents of <tt>/proc/PID/stat</tt> file.
047     */
048    public class Stat {
049        private static final Log fine = Log.fine(Stat.class);
050    
051        /**
052         * Create an unbounded Stat object.
053         */
054        public Stat() {
055        }
056    
057        public String toString() {
058            if (pid != null)
059                return "/proc/" + pid + "/stat";
060            else
061                return super.toString();
062        }
063    
064        /**
065         * Refresh Stat from <tt>/proc/PID/stat</tt>, return true if the
066         * scan was successful.  Returns false when the file doesn't
067         * exist, or can't be read.  Throws an error if there is some sort
068         * of scan problem.
069         */
070        public Stat scan(ProcessIdentifier pid) {
071            fine.log(this, "scan", pid);
072            return scan(pid.intValue());
073        }
074        private native Stat scan(int pid);
075        /**
076         * For testing; package-private.
077         */
078        native Stat scan(byte[] buf);
079        
080        /**
081         * Re-scan using the current pid.
082         */
083        public Stat rescan() {
084            return scan(pid.intValue());
085        }
086    
087        /**
088         * Refresh Stat from <tt>/proc/PID/task/TID/stat</tt>, return true if the
089         * scan was successful.  Returns false when the file doesn't
090         * exist, or can't be read.  Throws an error if there is some sort
091         * of scan problem.
092         */
093        public Stat scan(ProcessIdentifier pid, ProcessIdentifier tid) {
094            return scan(pid.intValue(), tid.intValue());
095        }
096        private native Stat scan(int pid, int tid);
097    
098        /** The thread id (== pid in main thread)  */
099        public ProcessIdentifier pid;
100        /** The filename of the executable.  */
101        public String comm;
102        /** The state represented by a character from "RSDZTW".  */
103        public char state;
104        /** The parent process id.  */
105        public ProcessIdentifier ppid;
106        /** The process group ID.  */
107        public int pgrp;
108        /** The session ID.  */
109        public int session;
110        /** The tty.  */
111        public int ttyNr;
112        /** The process group ID of the process that owns the tty.  */
113        public int tpgid;
114        /** The flags of the process.  */
115        public long flags;
116        /** The number of minor faults.  */
117        public long minflt;
118        /** The number of minor faults of the children.  */
119        public long cminflt;
120        /** The number of major faults.  */
121        public long majflt;
122        /** The number of major faluts of the children.  */
123        public long cmajflt;
124        /** The number of user mode jiffies.  */
125        public long utime;
126        /** The number of kernel mode jiffies.  */
127        public long stime;
128        /** The number of user mode child jiffies.  */
129        public long cutime;
130        /** The number of kernel mode child jiffies.  */
131        public long cstime;
132        /** The nice value (plus fifteen).  */
133        public long priority;
134        /** The nice value.  */
135        public int nice;
136        /** The number of threads (since 2.6).  */
137        public int numThreads;
138        /** The number of jiffies to the next SIGALRM.  */
139        public long irealvalue;
140        /** The number of jiffies, after system boot, that process started.  */
141        public long starttime;
142        /** Virtual memory size.  */
143        public long vsize;
144        /** Resident Set Size.  */
145        public long rss;
146        /** Current rss limit.  */
147        public long rlim;
148        /** The address above which program text can run.  */
149        public long startcode;
150        /** The address below which program text can run.  */
151        public long endcode;
152        /** The address of the start of the stack.  */
153        public long startstack;
154        /** The current value of the stack pointer.  */
155        public long kstkesp;
156        /** The current instruction pointer.  */
157        public long kstkeip;
158        /** The bitmap of pending signals.  */
159        public long signal;
160        /** The bitmap of blocked signals.  */
161        public long blocked;
162        /** The bitmap of ignored signals.  */
163        public long sigignore;
164        /** The bitmap of catched signals.  */
165        public long sigcatch;
166        /** The "channel" in which the process is waiting.  */
167        public long wchan;
168        /** Number of pages swapped.  */
169        public long nswap;
170        /** Number of pages swapped by children.  */
171        public long cnswap;
172        /** Signal to be sent to parent.  */
173        public int exitSignal;
174        /** CPU number last executed on.  */
175        public int processor;
176    }