summaryrefslogtreecommitdiffstats
path: root/base/process/process_info_mac.cc
blob: 22c61a8576a9a13c1b785a8bf8e29bc402bac4eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/process/process_info.h"

#include <stddef.h>
#include <sys/sysctl.h>
#include <sys/time.h>
#include <unistd.h>

#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/time/time.h"

namespace base {

// static
const Time CurrentProcessInfo::CreationTime() {
  int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() };
  size_t len = 0;
  if (sysctl(mib, arraysize(mib), NULL, &len, NULL, 0) < 0)
    return Time();

  scoped_ptr<struct kinfo_proc, base::FreeDeleter>
      proc(static_cast<struct kinfo_proc*>(malloc(len)));
  if (sysctl(mib, arraysize(mib), proc.get(), &len, NULL, 0) < 0)
    return Time();
  return Time::FromTimeVal(proc->kp_proc.p_un.__p_starttime);
}

}  // namespace base