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. Put application in background
Forum Updated to NodeBB v4.3 + New Features

Put application in background

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 2.7k Views 1 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.
  • L Offline
    L Offline
    luca
    wrote on last edited by
    #1

    Hi all,
    I'm working in Linux.
    If I need to execute a non-gui application in background I start it with:
    @
    ./myapp &
    @

    But what if I want the application to go in background itself ?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alexandros
      wrote on last edited by
      #2

      Hi, im working on ubuntu linux too.
      the way
      @./myapp &@
      is general and does not work only with non-gui applications, especially when you redirect you output to /dev/null so as to have a clear output, and, if in an interactive terminal to be able to access the terminal again by giving new commands.
      So, what do you actually mean 'go in background itself'?
      When you execute it to just launch and not append to it or what?
      Be more specific please :)
      yeee, my first post :)

      1 Reply Last reply
      0
      • L Offline
        L Offline
        luca
        wrote on last edited by
        #3

        I know there are some applications that starting without & character from a console go in background by itself.
        But I can be wrong... :-)

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dangelog
          wrote on last edited by
          #4

          In no particular order:

          • fork(2), then make the parent exit(2)
          • chdir(2) to "/" or some other safe working directory
          • close(2) all inherited file descriptors, including stdin, stdout and stderr. Eventually, reopen them on /dev/null using open(2) + dup2(2)
          • become a session leader with setsid(2)
          • create a new process group with setpgid(2)
          • detach from the controlling terminal by open(2) "/dev/tty", then using ioctl(2) TIOCNOTTY on it

          Much more details are available in any Unix programming book. See f.i. Advanced Programming in the Unix Environment by R. Stevens.

          Software Engineer
          KDAB (UK) Ltd., a KDAB Group company

          1 Reply Last reply
          0
          • L Offline
            L Offline
            luca
            wrote on last edited by
            #5

            [quote author="peppe" date="1307354561"]In no particular order:

            • fork(2), then make the parent exit(2)
            • chdir(2) to "/" or some other safe working directory
            • close(2) all inherited file descriptors, including stdin, stdout and stderr
            • become a session leader with setsid(2)
            • create a new process group with setpgid(2)
            • detach from the controlling terminal by open(2) "/dev/tty", then using ioctl(2) TIOCNOTTY on it

            Much more details are available in any Unix programming book. See f.i. Advanced Programming in the Unix Environment by R. Stevens.[/quote]

            Ok, so I think Qt can't do that... :-)

            I only used some times ago the "fork" solution.

            Thanks.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              alexandros
              wrote on last edited by
              #6

              Give me an example.
              For example, if you want gedit (GUI) to go in background, give
              @gedit& > /dev/null 2> /dev/null@
              If a program goes itself to the background, it just launches another instance of itself with other arguments but without appending to it and it just exits.
              For example, if you run myapp and it just launches, then it could be something
              @if(!QCoreApplication::arguments.count()>1){//no arguments
              //execute the same app here but with &
              //system() executes system commands and is more C than C++ but anyways
              system("myapp --justlaunched&");
              exit(2);
              }
              if(QCoreApplication::arguments.at(1)=="--justlaunched")
              mplamplampla@

              This is certainly a way to do it, but there may be a more efficient way for it, because this way cannot be used if you don't allow multiple instances of your program.

              1 Reply Last reply
              0

              • Login

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