1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/process_info.h"
7 #include <sys/sysctl.h>
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/time.h"
19 // Returns the process creation time, or NULL if an error occurred.
20 Time
* ProcessCreationTimeInternal() {
21 int mib
[] = { CTL_KERN
, KERN_PROC
, KERN_PROC_PID
, getpid() };
23 if (sysctl(mib
, arraysize(mib
), NULL
, &len
, NULL
, 0) < 0)
26 scoped_ptr_malloc
<struct kinfo_proc
>
27 proc(static_cast<struct kinfo_proc
*>(malloc(len
)));
28 if (sysctl(mib
, arraysize(mib
), proc
.get(), &len
, NULL
, 0) < 0)
30 return new Time(Time::FromTimeVal(proc
->kp_proc
.p_un
.__p_starttime
));
38 const Time
* CurrentProcessInfo::CreationTime() {
39 static Time
* process_creation_time
= ProcessCreationTimeInternal();
40 return process_creation_time
;