本文整理汇总了C++中process::MAX_REAP_INTERVAL方法的典型用法代码示例。如果您正苦于以下问题:C++ process::MAX_REAP_INTERVAL方法的具体用法?C++ process::MAX_REAP_INTERVAL怎么用?C++ process::MAX_REAP_INTERVAL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类process
的用法示例。
在下文中一共展示了process::MAX_REAP_INTERVAL方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: subprocess
TEST_F(SubprocessTest, SetupStatus)
{
// Exit 0 && setup 1.
Try<Subprocess> s = subprocess(
"exit 0",
Subprocess::FD(STDIN_FILENO),
Subprocess::FD(STDOUT_FILENO),
Subprocess::FD(STDERR_FILENO),
None(),
lambda::bind(&setupStatus, 1));
ASSERT_SOME(s);
// Advance time until the internal reaper reaps the subprocess.
Clock::pause();
while (s.get().status().isPending()) {
Clock::advance(MAX_REAP_INTERVAL());
Clock::settle();
}
Clock::resume();
AWAIT_ASSERT_READY(s.get().status());
ASSERT_SOME(s.get().status().get());
int status = s.get().status().get().get();
// Verify we received the setup returned value instead of the
// command status.
ASSERT_EQ(1, WEXITSTATUS(status));
// Exit 1 && setup 0.
s = subprocess(
"exit 1",
Subprocess::FD(STDIN_FILENO),
Subprocess::FD(STDOUT_FILENO),
Subprocess::FD(STDERR_FILENO),
None(),
lambda::bind(&setupStatus, 0));
ASSERT_SOME(s);
// Advance time until the internal reaper reaps the subprocess.
Clock::pause();
while (s.get().status().isPending()) {
Clock::advance(MAX_REAP_INTERVAL());
Clock::settle();
}
Clock::resume();
AWAIT_ASSERT_READY(s.get().status());
ASSERT_SOME(s.get().status().get());
status = s.get().status().get().get();
// Verify we received the command status.
ASSERT_EQ(1, WEXITSTATUS(status));
}
示例2: Fork
// This test checks that we can reap a non-child process, in terms
// of receiving the termination notification.
TEST(ReapTest, NonChildProcess)
{
// The child process creates a grandchild and then exits. The
// grandchild sleeps for 10 seconds. The process tree looks like:
// -+- child exit 0
// \-+- grandchild sleep 10
// After the child exits, the grandchild is going to be re-parented
// by 'init', like this:
// -+- child (exit 0)
// -+- grandchild sleep 10
Try<ProcessTree> tree = Fork(None(),
Fork(Exec(SLEEP_COMMAND(10))),
Exec("exit 0"))();
ASSERT_SOME(tree);
ASSERT_EQ(1u, tree.get().children.size());
pid_t grandchild = tree.get().children.front();
// Reap the grandchild process.
Future<Option<int>> status = process::reap(grandchild);
EXPECT_TRUE(status.isPending());
// Now kill the grandchild.
// NOTE: We send a SIGKILL here because sometimes the grandchild
// process seems to be in a hung state and not responding to
// SIGTERM/SIGINT.
EXPECT_EQ(0, kill(grandchild, SIGKILL));
Clock::pause();
// Now advance time until the Reaper reaps the grandchild.
while (status.isPending()) {
Clock::advance(MAX_REAP_INTERVAL());
Clock::settle();
}
AWAIT_READY(status);
// The status is None because pid is not an immediate child.
ASSERT_NONE(status.get()) << status.get().get();
// Reap the child as well to clean up after ourselves.
status = process::reap(tree.get().process.pid);
// Now advance time until the child is reaped.
while (status.isPending()) {
Clock::advance(MAX_REAP_INTERVAL());
Clock::settle();
}
// Check if the status is correct.
AWAIT_EXPECT_WEXITSTATUS_EQ(0, status);
Clock::resume();
}
示例3: Seconds
TEST_F(SubprocessTest, Flags)
{
Flags flags;
flags.b = true;
flags.i = 42;
flags.s = "hello";
flags.s2 = "we're";
flags.s3 = "\"geek\"";
flags.d = Seconds(10);
flags.y = Bytes(100);
JSON::Object object;
object.values["strings"] = "string";
object.values["integer1"] = 1;
object.values["integer2"] = -1;
object.values["double1"] = 1;
object.values["double2"] = -1;
object.values["double3"] = -1.42;
JSON::Object nested;
nested.values["string"] = "string";
object.values["nested"] = nested;
JSON::Array array;
array.values.push_back(nested);
object.values["array"] = array;
flags.j = object;
string out = path::join(os::getcwd(), "stdout");
Try<Subprocess> s = subprocess(
"/bin/echo",
vector<string>(1, "echo"),
Subprocess::FD(STDIN_FILENO),
Subprocess::PATH(out),
Subprocess::FD(STDERR_FILENO),
flags);
ASSERT_SOME(s);
// Advance time until the internal reaper reaps the subprocess.
Clock::pause();
while (s.get().status().isPending()) {
Clock::advance(MAX_REAP_INTERVAL());
Clock::settle();
}
Clock::resume();
AWAIT_ASSERT_READY(s.get().status());
ASSERT_SOME(s.get().status().get());
int status = s.get().status().get().get();
EXPECT_TRUE(WIFEXITED(status));
EXPECT_EQ(0, WEXITSTATUS(status));
// Parse the output and make sure that it matches the flags we
// specified in the beginning.
Try<string> read = os::read(out);
ASSERT_SOME(read);
// TODO(jieyu): Consider testing the case where escaped spaces exist
// in the arguments.
vector<string> split = strings::split(read.get(), " ");
int argc = split.size() + 1;
char** argv = new char*[argc];
argv[0] = (char*) "command";
for (int i = 1; i < argc; i++) {
argv[i] = ::strdup(split[i - 1].c_str());
}
Flags flags2;
Try<Nothing> load = flags2.load(None(), argc, argv);
ASSERT_SOME(load);
EXPECT_EQ(flags.b, flags2.b);
EXPECT_EQ(flags.i, flags2.i);
EXPECT_EQ(flags.s, flags2.s);
EXPECT_EQ(flags.s2, flags2.s2);
EXPECT_EQ(flags.s3, flags2.s3);
EXPECT_EQ(flags.d, flags2.d);
EXPECT_EQ(flags.y, flags2.y);
EXPECT_EQ(flags.j, flags2.j);
for (int i = 1; i < argc; i++) {
::free(argv[i]);
}
delete[] argv;
}