class Poco::Process

Overview

This class provides methods for working with processes. Moreā€¦

#include <Process.h>

class Process: public Poco::ProcessImpl
{
public:
    // typedefs

    typedef PIDImpl PID;
    typedef ArgsImpl Args;
    typedef EnvImpl Env;

    // methods

    static
    PID
    id();

    static
    void
    times(
        long& userTime,
        long& kernelTime
        );

    static
    ProcessHandle
    launch(
        const std::string& command,
        const Args& args
        );

    static
    ProcessHandle
    launch(
        const std::string& command,
        const Args& args,
        const std::string& initialDirectory
        );

    static
    ProcessHandle
    launch(
        const std::string& command,
        const Args& args,
        Pipe* inPipe,
        Pipe* outPipe,
        Pipe* errPipe
        );

    static
    ProcessHandle
    launch(
        const std::string& command,
        const Args& args,
        const std::string& initialDirectory,
        Pipe* inPipe,
        Pipe* outPipe,
        Pipe* errPipe
        );

    static
    ProcessHandle
    launch(
        const std::string& command,
        const Args& args,
        Pipe* inPipe,
        Pipe* outPipe,
        Pipe* errPipe,
        const Env& env
        );

    static
    ProcessHandle
    launch(
        const std::string& command,
        const Args& args,
        const std::string& initialDirectory,
        Pipe* inPipe,
        Pipe* outPipe,
        Pipe* errPipe,
        const Env& env
        );

    static
    int
    wait(const ProcessHandle& handle);

    static
    bool
    isRunning(const ProcessHandle& handle);

    static
    bool
    isRunning(PID pid);

    static
    void
    kill(ProcessHandle& handle);

    static
    void
    kill(PID pid);

    static
    void
    requestTermination(PID pid);
};

Inherited Members

public:
    // typedefs

    typedef pid_t PIDImpl;
    typedef int PIDImpl;
    typedef UInt32 PIDImpl;
    typedef std::vector<std::string> ArgsImpl;
    typedef std::map<std::string, std::string> EnvImpl;

    // methods

    static
    int
    waitImpl(PIDImpl pid);

    static
    PIDImpl
    idImpl();

    static
    void
    timesImpl(
        long& userTime,
        long& kernelTime
        );

    static
    ProcessHandleImpl*
    launchImpl(
        const std::string& command,
        const ArgsImpl& args,
        const std::string& initialDirectory,
        Pipe* inPipe,
        Pipe* outPipe,
        Pipe* errPipe,
        const EnvImpl& env
        );

    static
    void
    killImpl(ProcessHandleImpl& handle);

    static
    void
    killImpl(PIDImpl pid);

    static
    bool
    isRunningImpl(const ProcessHandleImpl& handle);

    static
    bool
    isRunningImpl(PIDImpl pid);

    static
    void
    requestTerminationImpl(PIDImpl pid);

    static
    std::string
    terminationEventName(PIDImpl pid);

Detailed Documentation

This class provides methods for working with processes.

Methods

static
PID
id()

Returns the process ID of the current process.

static
void
times(
    long& userTime,
    long& kernelTime
    )

Returns the number of seconds spent by the current process in user and kernel mode.

static
ProcessHandle
launch(
    const std::string& command,
    const Args& args
    )

Creates a new process for the given command and returns a ProcessHandle of the new process.

The given arguments are passed to the command on the command line.

static
int
wait(const ProcessHandle& handle)

Waits for the process specified by handle to terminate and returns the exit code of the process.

static
bool
isRunning(const ProcessHandle& handle)

check if the process specified by handle is running or not

This is preferable on Windows where process IDs may be reused.

static
bool
isRunning(PID pid)

Check if the process specified by given pid is running or not.

static
void
kill(ProcessHandle& handle)

Kills the process specified by handle.

This is preferable on Windows where process IDs may be reused.

static
void
kill(PID pid)

Kills the process with the given pid.

static
void
requestTermination(PID pid)

Requests termination of the process with the give PID.

On Unix platforms, this will send a SIGINT to the process and thus work with arbitrary processes.

On other platforms, a global event flag will be set. Setting the flag will cause Util::ServerApplication::waitForTerminationRequest() to return. Therefore this will only work with applications based on Util::ServerApplication.