annotate base/System.cpp @ 101:ce1d385f4f89

* Use kill(pid, 0) instead of /proc or sysctl blather for looking up pids * Add OpenProcess call for Win32
author Chris Cannam
date Fri, 05 May 2006 12:34:51 +0000
parents 604bd4ee3ed4
children 173b39ea0728
rev   line source
Chris@49 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@52 4 Sonic Visualiser
Chris@52 5 An audio file viewer and annotation editor.
Chris@52 6 Centre for Digital Music, Queen Mary, University of London.
Chris@52 7 This file copyright 2006 Chris Cannam.
Chris@0 8
Chris@52 9 This program is free software; you can redistribute it and/or
Chris@52 10 modify it under the terms of the GNU General Public License as
Chris@52 11 published by the Free Software Foundation; either version 2 of the
Chris@52 12 License, or (at your option) any later version. See the file
Chris@52 13 COPYING included with this distribution for more information.
Chris@0 14 */
Chris@0 15
Chris@0 16 #include "System.h"
Chris@0 17
Chris@98 18 #ifndef _WIN32
Chris@101 19 #include <signal.h>
Chris@98 20 #endif
Chris@98 21
Chris@98 22 #include <iostream>
Chris@98 23
Chris@0 24 #ifdef _WIN32
Chris@0 25
Chris@0 26 extern "C" {
Chris@0 27
Chris@0 28 void gettimeofday(struct timeval *tv, void *tz)
Chris@0 29 {
Chris@0 30 union {
Chris@0 31 long long ns100;
Chris@0 32 FILETIME ft;
Chris@0 33 } now;
Chris@0 34
Chris@0 35 GetSystemTimeAsFileTime(&now.ft);
Chris@0 36 tv->tv_usec = (long)((now.ns100 / 10LL) % 1000000LL);
Chris@0 37 tv->tv_sec = (long)((now.ns100 - 116444736000000000LL) / 10000000LL);
Chris@0 38 }
Chris@0 39
Chris@0 40 }
Chris@0 41
Chris@0 42 #endif
Chris@98 43
Chris@98 44 ProcessStatus
Chris@98 45 GetProcessStatus(int pid)
Chris@98 46 {
Chris@101 47 #ifdef _WIN32
Chris@101 48 DWORD handle = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid);
Chris@101 49 if (!handle) {
Chris@101 50 return ProcessNotRunning;
Chris@101 51 } else {
Chris@101 52 CloseHandle(handle);
Chris@101 53 return ProcessRunning;
Chris@101 54 }
Chris@101 55 #else
Chris@101 56 if (kill(getpid(), 0) == 0) {
Chris@101 57 if (kill(pid, 0) == 0) {
Chris@101 58 return ProcessRunning;
Chris@101 59 } else {
Chris@101 60 return ProcessNotRunning;
Chris@101 61 }
Chris@101 62 } else {
Chris@98 63 return UnknownProcessStatus;
Chris@98 64 }
Chris@98 65 #endif
Chris@98 66 }
Chris@98 67