Giter Site home page Giter Site logo

Question for Tutorial code about process HOT 5 CLOSED

boostorg avatar boostorg commented on June 17, 2024
Question for Tutorial code

from process.

Comments (5)

klemens-morgenstern avatar klemens-morgenstern commented on June 17, 2024 2

The warning shouldn't be there (anymore). The pipe-sink is closed on the parent side, so there won't be any deadlock.

Nm also writes out an empty line at the end, so it would be fine otherwise.

from process.

tanxn5 avatar tanxn5 commented on June 17, 2024 1

Thanks. maybe i misunderstood something, this routine:

  1. c.runing() = true
  2. (nm exited...)
  3. std::getline(is, line) ---> is it safe?

because there is a tutorial warning

Warning
--
The pipe will cause a deadlock if you try to read after nm exited

from process.

klemens-morgenstern avatar klemens-morgenstern commented on June 17, 2024

Then the loop condition isn't fulfilled and child.wait reaps the zombie process from the table.

from process.

tanxn5 avatar tanxn5 commented on June 17, 2024

Thanks.

from process.

vt-alt avatar vt-alt commented on June 17, 2024

@klemens-morgenstern But aren't FAQ is incorrect too?

[section:closep Why does the pipe not close?]

Now for another example, which might look correct, let's consider you want
to use `ls` to read the current directory.

ipstream is;
child c("ls", std_out > is);

std::string file;
while (is >> file)
    cout << "File: " << file << endl;


This will also deadlock, because the pipe does not close when the subprocess exits.
So the `ipstream` will still look for data even though the process has ended.

[note It is not possible to use automatic pipe-closing in this library, because
a pipe might be a file-handle (as for async pipes on windows).]

The example code does not deadlock anymore too.

from process.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.