Process.h 925 Bytes
Newer Older
1
/*
xiongziliang committed
2
 * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
xiongziliang committed
3
 *
4
 * This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
xiongziliang committed
5
 *
xiongziliang committed
6 7 8
 * Use of this source code is governed by MIT license that can be found in the
 * LICENSE file in the root of the source tree. All contributing project authors
 * may be found in the AUTHORS file in the root of the source tree.
xiongziliang committed
9
 */
xiongziliang committed
10

11 12
#ifndef ZLMEDIAKIT_PROCESS_H
#define ZLMEDIAKIT_PROCESS_H
13

14 15 16
#ifdef _WIN32
typedef int pid_t;
#else
17
#include <sys/wait.h>
18 19
#endif // _WIN32

20
#include <fcntl.h>
21 22 23 24 25 26 27 28
#include <string>
using namespace std;

class Process {
public:
    Process();
    ~Process();
    void run(const string &cmd,const string &log_file);
29
    void kill(int max_delay,bool force = false);
30 31 32 33
    bool wait(bool block = true);
    int exit_code();
private:
    pid_t _pid = -1;
xiongziliang committed
34
    void *_handle = nullptr;
35 36 37 38
    int _exit_code = 0;
};


39
#endif //ZLMEDIAKIT_PROCESS_H