MCPcopy Create free account
hub / github.com/prometheus/procfs / Stat

Method Stat

proc_stat.go:136–211  ·  view source on GitHub ↗

Stat returns the current status information of the process.

()

Source from the content-addressed store, hash-verified

134
135// Stat returns the current status information of the process.
136func (p Proc) Stat() (ProcStat, error) {
137 data, err := parsers.ReadFileNoStat(p.path("stat"))
138 if err != nil {
139 return ProcStat{}, err
140 }
141
142 var (
143 ignoreInt64 int64
144 ignoreUint64 uint64
145
146 s = ProcStat{PID: p.PID, proc: p.fs}
147 l = bytes.Index(data, []byte("("))
148 r = bytes.LastIndex(data, []byte(")"))
149 )
150
151 if l < 0 || r < 0 {
152 return ProcStat{}, fmt.Errorf("%w: unexpected format, couldn't extract comm %q", ErrFileParse, data)
153 }
154
155 s.Comm = string(data[l+1 : r])
156
157 // Check the following resources for the details about the particular stat
158 // fields and their data types:
159 // * https://man7.org/linux/man-pages/man5/proc.5.html
160 // * https://man7.org/linux/man-pages/man3/scanf.3.html
161 _, err = fmt.Fscan(
162 bytes.NewBuffer(data[r+2:]),
163 &s.State,
164 &s.PPID,
165 &s.PGRP,
166 &s.Session,
167 &s.TTY,
168 &s.TPGID,
169 &s.Flags,
170 &s.MinFlt,
171 &s.CMinFlt,
172 &s.MajFlt,
173 &s.CMajFlt,
174 &s.UTime,
175 &s.STime,
176 &s.CUTime,
177 &s.CSTime,
178 &s.Priority,
179 &s.Nice,
180 &s.NumThreads,
181 &ignoreInt64,
182 &s.Starttime,
183 &s.VSize,
184 &s.RSS,
185 &s.RSSLimit,
186 &s.StartCode,
187 &s.EndCode,
188 &s.StartStack,
189 &ignoreUint64,
190 &ignoreUint64,
191 &ignoreUint64,
192 &ignoreUint64,
193 &ignoreUint64,

Callers 2

NewStatMethod · 0.95
StartTimeMethod · 0.45

Calls 2

pathMethod · 0.95
ReadFileNoStatFunction · 0.92

Tested by

no test coverage detected