Kill processes recursively by their process ids given in a file

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I want to be able to kill some processes.
I know the process id (that is given in file) and I do not want to do it one by one. Is there any way to do it something like calling kill command recursively and giving it input through file or standard input like we do with rm command...







share|improve this question


















  • 1




    I don't know what you mean by "recursively", and rm does not read from standard input.
    – Kusalananda
    Mar 31 at 12:25














up vote
0
down vote

favorite












I want to be able to kill some processes.
I know the process id (that is given in file) and I do not want to do it one by one. Is there any way to do it something like calling kill command recursively and giving it input through file or standard input like we do with rm command...







share|improve this question


















  • 1




    I don't know what you mean by "recursively", and rm does not read from standard input.
    – Kusalananda
    Mar 31 at 12:25












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I want to be able to kill some processes.
I know the process id (that is given in file) and I do not want to do it one by one. Is there any way to do it something like calling kill command recursively and giving it input through file or standard input like we do with rm command...







share|improve this question














I want to be able to kill some processes.
I know the process id (that is given in file) and I do not want to do it one by one. Is there any way to do it something like calling kill command recursively and giving it input through file or standard input like we do with rm command...









share|improve this question













share|improve this question




share|improve this question








edited Mar 31 at 12:23









Kusalananda

102k13201317




102k13201317










asked Mar 31 at 12:05









Ashu

51




51







  • 1




    I don't know what you mean by "recursively", and rm does not read from standard input.
    – Kusalananda
    Mar 31 at 12:25












  • 1




    I don't know what you mean by "recursively", and rm does not read from standard input.
    – Kusalananda
    Mar 31 at 12:25







1




1




I don't know what you mean by "recursively", and rm does not read from standard input.
– Kusalananda
Mar 31 at 12:25




I don't know what you mean by "recursively", and rm does not read from standard input.
– Kusalananda
Mar 31 at 12:25










1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










Given a file, pids.txt, with one process ID per line, you may do



xargs kill <pids.txt


This will invoke the kill utility with the process IDs from the file.



Other solutions include



kill $(cat pids.txt)


which IMHO is not so elegant, and



while read pid; do
kill "$pid"
done <pids.txt


which is a lot to write to do a simple thing.




Note that none of the above variations are able to verify that the process IDs in the text file corresponds to the same processes that the process IDs were attached to at the time of creating the file.



On Linux systems, process IDs are usually incremented by one for each new process, and when the maximum allowed process ID has been used, the further IDs are allocated from some low number. This means that process IDs, over time, are re-used.



On some systems, like OpenBSD, process IDs are randomly allocated. Here too, there will be re-use of old process IDs after some time.






share|improve this answer






















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );








     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f434659%2fkill-processes-recursively-by-their-process-ids-given-in-a-file%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    Given a file, pids.txt, with one process ID per line, you may do



    xargs kill <pids.txt


    This will invoke the kill utility with the process IDs from the file.



    Other solutions include



    kill $(cat pids.txt)


    which IMHO is not so elegant, and



    while read pid; do
    kill "$pid"
    done <pids.txt


    which is a lot to write to do a simple thing.




    Note that none of the above variations are able to verify that the process IDs in the text file corresponds to the same processes that the process IDs were attached to at the time of creating the file.



    On Linux systems, process IDs are usually incremented by one for each new process, and when the maximum allowed process ID has been used, the further IDs are allocated from some low number. This means that process IDs, over time, are re-used.



    On some systems, like OpenBSD, process IDs are randomly allocated. Here too, there will be re-use of old process IDs after some time.






    share|improve this answer


























      up vote
      1
      down vote



      accepted










      Given a file, pids.txt, with one process ID per line, you may do



      xargs kill <pids.txt


      This will invoke the kill utility with the process IDs from the file.



      Other solutions include



      kill $(cat pids.txt)


      which IMHO is not so elegant, and



      while read pid; do
      kill "$pid"
      done <pids.txt


      which is a lot to write to do a simple thing.




      Note that none of the above variations are able to verify that the process IDs in the text file corresponds to the same processes that the process IDs were attached to at the time of creating the file.



      On Linux systems, process IDs are usually incremented by one for each new process, and when the maximum allowed process ID has been used, the further IDs are allocated from some low number. This means that process IDs, over time, are re-used.



      On some systems, like OpenBSD, process IDs are randomly allocated. Here too, there will be re-use of old process IDs after some time.






      share|improve this answer
























        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        Given a file, pids.txt, with one process ID per line, you may do



        xargs kill <pids.txt


        This will invoke the kill utility with the process IDs from the file.



        Other solutions include



        kill $(cat pids.txt)


        which IMHO is not so elegant, and



        while read pid; do
        kill "$pid"
        done <pids.txt


        which is a lot to write to do a simple thing.




        Note that none of the above variations are able to verify that the process IDs in the text file corresponds to the same processes that the process IDs were attached to at the time of creating the file.



        On Linux systems, process IDs are usually incremented by one for each new process, and when the maximum allowed process ID has been used, the further IDs are allocated from some low number. This means that process IDs, over time, are re-used.



        On some systems, like OpenBSD, process IDs are randomly allocated. Here too, there will be re-use of old process IDs after some time.






        share|improve this answer














        Given a file, pids.txt, with one process ID per line, you may do



        xargs kill <pids.txt


        This will invoke the kill utility with the process IDs from the file.



        Other solutions include



        kill $(cat pids.txt)


        which IMHO is not so elegant, and



        while read pid; do
        kill "$pid"
        done <pids.txt


        which is a lot to write to do a simple thing.




        Note that none of the above variations are able to verify that the process IDs in the text file corresponds to the same processes that the process IDs were attached to at the time of creating the file.



        On Linux systems, process IDs are usually incremented by one for each new process, and when the maximum allowed process ID has been used, the further IDs are allocated from some low number. This means that process IDs, over time, are re-used.



        On some systems, like OpenBSD, process IDs are randomly allocated. Here too, there will be re-use of old process IDs after some time.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 31 at 12:32

























        answered Mar 31 at 12:24









        Kusalananda

        102k13201317




        102k13201317






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f434659%2fkill-processes-recursively-by-their-process-ids-given-in-a-file%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?