Results 1 to 10 of 10

Thread: Kill a Process started with Qprocess ??

  1. #1
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Kill a Process started with Qprocess ??

    Hello Guys,

    I am using Qprocess to start an application, which will run for long time.

    but i want to be able to kill this application after i start it, i tried to kill my Qprocess that i used to start that application but that did not work
    as the Qprocess will has its own process and the application has different process after i start it.

    i tried to use the pid(), but its the same too, where the pid() i get is the process id for the Qprocess not the application.

    so could you please help me who can reach the application process and how can i kill it ??

    Thank you

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Kill a Process started with Qprocess ??

    What exactly did you try?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Kill a Process started with Qprocess ??

    well

    first i have myQprocess started my Application.

    myQprcess.start(MyApplicatoin);

    then i tried to stop my application from running,
    i tried
    myQprocess.kill();

    this did not work.

    then i tired to get the process id ,that is running the application.

    qint64 id myQporcess.pid();

    the id that i got is different than the process id that is running my application

    when i used the "top" command to see the process id they are different, not the same.

    so i dont know how can related between myQprocess and the process that is running my application, and how can i stop/kill it.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Kill a Process started with Qprocess ??

    Please show your exact code, not pseudocode.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Kill a Process started with Qprocess ??

    well, i think i have to because you can not run the same application i'm running.

    Let me give try to make it more clear:

    Qt Code:
    1. void MyWindow::startApp(QString Command)
    2. {
    3. /* command = " Run -nn 1 -np 12 myApp"
    4. where :
    5.   nn: number of nodes i want to use
    6.   np: number of processes per each node */
    7.  
    8. Myprocess->start(Command);
    9.  
    10. //I catch all the signals from the Myprcess , readyread, fininshe ..etc
    11. }
    12.  
    13. void MyWindow::stopApp()
    14. {
    15.  
    16. qint64 id = Myprocess->pid();
    17. qDebug() << QString::number(id); // just to know the process id the was started before i kill it.
    18.  
    19. Myprocess->kill();
    20.  
    21. }
    To copy to clipboard, switch view to plain text mode 

    This is what i am doing.
    so now i am just using one node, which my local machine, and forking 12 processes to run the application.

    Now when i use the terminal to show the processes i have.

    // the process id that im getting from Myprocess.pid() is >> 62524

    before kill
    qgrep Myapp.exe

    result:
    62524
    64073
    64074
    64075
    64076
    64077
    64078
    64079
    64080
    64081
    64082
    64083


    After Kill

    pgrep myApp.exe

    64073
    64074
    64075
    64076
    64077
    64078
    64079
    64080
    64081
    64082
    64083

    only the first process get killed which the parent process that lead to fork all the other processes but the other process continue to works and the application too.

    hope this make it more clear.

    Thanks

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Kill a Process started with Qprocess ??

    So everything works fine. You are killing the process you started with QProcess. If those other processes have detatched from their parent, you have no control over them anymore. It's not a matter of QProcess but rather how your "Run" program works.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Kill a Process started with Qprocess ??

    Here i think i figure out what is my problem is :

    1- I am using kill() witch will raise SIGKILL signal will send to the process which will not give it time to end all the other processes and clean.
    I need to use terminate() witch will send SIGTERM signal to all it to end all the forked processes and end cleanly.

    2- the command i using is actually calling a script witch will launch the real application.
    so myQprocess has the idea for the script and when i kill it or terminate it, it wont affect the real application, it just ends the script with already started the application.

    so what i think i need to do is to find a way to handle the child of myQprocess.

    Is there away to reach the child of Qprocess ??

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Kill a Process started with Qprocess ??

    What child? There is no child of QProcess.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Kill a Process started with Qprocess ??

    the Qprocess make process to run the script, which will for a process to run the app.

    so is not the process that was created by the script to run the app, is a child process to the process that is running the script ??

    its a bit confusing

    qprocess >>
    run scrpit >>
    run app.

    is not run app is a child to qprocess ??

    in numbers:

    MyQprocess.start("script");

    pgrep myapp

    62011
    62012

    MyQprocess.pid() //= 62011

    but 62012 is created by 62011 which The Qprocess.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Kill a Process started with Qprocess ??

    Again, if the child process forks and creates a number of other processes that detach from their parent, you have no control over them. You could probably use platform dependent means to get a list of pids of child processes of a process but that's outside the scope of this forum.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. The following user says thank you to wysota for this useful post:

    jesse_mark (30th November 2012)

Similar Threads

  1. Replies: 4
    Last Post: 3rd June 2012, 06:45
  2. problem about kill a QProcess
    By Raul in forum Qt Programming
    Replies: 2
    Last Post: 8th June 2010, 10:50
  3. Detect First QProcess finished in a group and kill other
    By Davidaino in forum Qt Programming
    Replies: 3
    Last Post: 11th July 2008, 12:53
  4. Questions about kill() and start() of QProcess
    By mp33919 in forum Qt Programming
    Replies: 5
    Last Post: 23rd June 2007, 13:00
  5. Replies: 2
    Last Post: 30th March 2007, 08:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.