Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can QProcess runs eventloop without starting external program?
Qt 6.11 is out! See what's new in the release blog

Can QProcess runs eventloop without starting external program?

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 3.6k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    FloatFlower.Huang
    wrote on last edited by FloatFlower.Huang
    #1

    I want to write a multi-process program and I want to make parent process as works dispatcher and make all child processes as worker. Parent process dispatches works with channel. Can Qt possible to implement?

    I check out the documentation from : http://doc.qt.io/qt-5/qprocess.html, and found that all QProcess::start() functions are required programName is set.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi! Yes that's possible, no problem. QProcess offers an asynchronous API for talking to the child process it manages. You can have as many child processes as you wish. You need one QProcess object per child process.

      F 1 Reply Last reply
      0
      • ? A Former User

        Hi! Yes that's possible, no problem. QProcess offers an asynchronous API for talking to the child process it manages. You can have as many child processes as you wish. You need one QProcess object per child process.

        F Offline
        F Offline
        FloatFlower.Huang
        wrote on last edited by
        #3

        @Wieland

        I want to do like this

        pid_t pid = fork();
        if (pid == 0)
        {
          // child process do work
        }
        else {
          // parent process do work
        }
        

        However, QProcess looks like only provide API to start external program. Is any way to execute code but not a program?

        jsulmJ JonBJ 2 Replies Last reply
        0
        • F FloatFlower.Huang

          @Wieland

          I want to do like this

          pid_t pid = fork();
          if (pid == 0)
          {
            // child process do work
          }
          else {
            // parent process do work
          }
          

          However, QProcess looks like only provide API to start external program. Is any way to execute code but not a program?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by jsulm
          #4

          @FloatFlower.Huang To me your use case sounds more like something for multithreading. Why do you want to use processes?
          "execute code but not a program" - a process always executes a program.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            Oh, I see. No, you can't use QProcess here and there's no other Qt API for this. Just take the usual POSIX / Windows stuff (fork, clone, pipes, etc).

            1 Reply Last reply
            1
            • F FloatFlower.Huang

              @Wieland

              I want to do like this

              pid_t pid = fork();
              if (pid == 0)
              {
                // child process do work
              }
              else {
                // parent process do work
              }
              

              However, QProcess looks like only provide API to start external program. Is any way to execute code but not a program?

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @FloatFlower.Huang
              Qt concerns itself mainly with cross-platform solutions. What you want to do is highly Linux-only: try implementing fork() under Windows! It doesn't work like that.

              QProcess is about spawning a separate sub-process. As @jsulm says, surely you want to use Qt threading here?

              1 Reply Last reply
              0
              • F Offline
                F Offline
                FloatFlower.Huang
                wrote on last edited by
                #7

                @jsulm @JNBarchan

                I am going to implement multi-process and each process manage many threads just like Nginx HTTP server. In Nginx HTTP server, the master process fork multiple worker threads and each process have many threads to handle requests. Because there is limit amount of threads per process, so I am thinking about how to increase the thread amount in the program.

                jsulmJ 2 Replies Last reply
                0
                • F FloatFlower.Huang

                  @jsulm @JNBarchan

                  I am going to implement multi-process and each process manage many threads just like Nginx HTTP server. In Nginx HTTP server, the master process fork multiple worker threads and each process have many threads to handle requests. Because there is limit amount of threads per process, so I am thinking about how to increase the thread amount in the program.

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @FloatFlower.Huang Well, you can use QProcess for that. You can even start same app using it, just pass parameters to it tell it what it should do.

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • F FloatFlower.Huang

                    @jsulm @JNBarchan

                    I am going to implement multi-process and each process manage many threads just like Nginx HTTP server. In Nginx HTTP server, the master process fork multiple worker threads and each process have many threads to handle requests. Because there is limit amount of threads per process, so I am thinking about how to increase the thread amount in the program.

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @FloatFlower.Huang said in Can QProcess runs eventloop without starting external program?:

                    Because there is limit amount of threads per process, so I am thinking about how to increase the thread amount in the program.

                    Don't do this! Just make sure not to exceed this limit. If you reach the limit queue other jobs and take them from the queue as soon as a thread is free. Threads and even more so processes consume ressources like memory, CPU and operating system resources. It does not make sense to have too many threads because the overhead to manage them will become too high and you will not get any performance improvements anymore.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    2

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved