Chris@49: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@0: Chris@0: /* Chris@52: Sonic Visualiser Chris@52: An audio file viewer and annotation editor. Chris@52: Centre for Digital Music, Queen Mary, University of London. Chris@52: This file copyright 2006 Chris Cannam. Chris@0: Chris@52: This program is free software; you can redistribute it and/or Chris@52: modify it under the terms of the GNU General Public License as Chris@52: published by the Free Software Foundation; either version 2 of the Chris@52: License, or (at your option) any later version. See the file Chris@52: COPYING included with this distribution for more information. Chris@0: */ Chris@0: Chris@0: #include "System.h" Chris@0: Chris@98: #ifndef _WIN32 Chris@101: #include Chris@98: #endif Chris@98: Chris@98: #include Chris@98: Chris@0: #ifdef _WIN32 Chris@0: Chris@0: extern "C" { Chris@0: Chris@0: void gettimeofday(struct timeval *tv, void *tz) Chris@0: { Chris@0: union { Chris@0: long long ns100; Chris@0: FILETIME ft; Chris@0: } now; Chris@0: Chris@0: GetSystemTimeAsFileTime(&now.ft); Chris@0: tv->tv_usec = (long)((now.ns100 / 10LL) % 1000000LL); Chris@0: tv->tv_sec = (long)((now.ns100 - 116444736000000000LL) / 10000000LL); Chris@0: } Chris@0: Chris@0: } Chris@0: Chris@0: #endif Chris@98: Chris@98: ProcessStatus Chris@98: GetProcessStatus(int pid) Chris@98: { Chris@101: #ifdef _WIN32 Chris@101: DWORD handle = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid); Chris@101: if (!handle) { Chris@101: return ProcessNotRunning; Chris@101: } else { Chris@101: CloseHandle(handle); Chris@101: return ProcessRunning; Chris@101: } Chris@101: #else Chris@101: if (kill(getpid(), 0) == 0) { Chris@101: if (kill(pid, 0) == 0) { Chris@101: return ProcessRunning; Chris@101: } else { Chris@101: return ProcessNotRunning; Chris@101: } Chris@101: } else { Chris@98: return UnknownProcessStatus; Chris@98: } Chris@98: #endif Chris@98: } Chris@98: