How to delete multiple process id of a single process?How to use single-thread script to do batch processing?How to write a shscript to kill -9 a pid which is found via lsof -iBash file for sending a signal to a processHow to avoid killing the wrong process in a bash script?How can I kill a process with a phrase in its name?Ubuntu 16.04 /bin/kill bug?Kill all the other instances of a running process except the very first oneHelp deciphering `ps` and `pstree` with `cron` and `sudo`Interrupt the bash script with SIGINTRunning pgrep in a crontab

Was adding milk to tea started to reduce employee tea break time?

Are randomly-generated passwords starting with "a" less secure?

Am I testing diodes properly?

Referring to different instances of the same character in time travel

Redirect https to fqdn

Supporting developers who insist on using their pet language

Why did my rum cake turn black?

As the Dungeon Master, how do I handle a player that insists on a specific class when I already know that choice will cause issues?

Where is the USB2 OTG port on the RPi 4 Model B located?

Why can't supermassive black holes merge? (or can they?)

How can one write good dialogue in a story without sounding wooden?

Did any of the founding fathers anticipate Lysander Spooner's criticism of the constitution?

During copyediting, journal disagrees about spelling of paper's main topic

Why are Hobbits so fond of mushrooms?

I quit, and boss offered me 3 month "grace period" where I could still come back

Why does resistance reduce when a conductive fabric is stretched?

Can I use "candidate" as a verb?

Is purchasing foreign currency before going abroad a losing proposition?

How do Windows version numbers work?

What would the EU do if an EU member declared war on another EU member?

What is this welding tool I found in my attic?

What is temperature on a quantum level

Is Arc Length always irrational between two rational points?

<schwitz>, <zwinker> etc. Does German always use 2nd Person Singular Imperative verbs for emoticons? If so, why?



How to delete multiple process id of a single process?


How to use single-thread script to do batch processing?How to write a shscript to kill -9 a pid which is found via lsof -iBash file for sending a signal to a processHow to avoid killing the wrong process in a bash script?How can I kill a process with a phrase in its name?Ubuntu 16.04 /bin/kill bug?Kill all the other instances of a running process except the very first oneHelp deciphering `ps` and `pstree` with `cron` and `sudo`Interrupt the bash script with SIGINTRunning pgrep in a crontab






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








3















I'm using the following code to kill all the PID's of a certain process, but its not working as expected.



pgrep -f <processname>

kill -9 $(pgrep -f <processname>)


when there are more than one PID, the above line throws error stating :




too many arguments.











share|improve this question
























  • What if you remove the -f? That exact same command (except for the -f) works for me in killing Chromium.

    – RonJohn
    Jul 4 at 20:41











  • A little nitpick: there's no such thing as "multiple process IDs of a single process". Each process has one PID. (Unless you count its threads, which I don't) What this question is about is killing all the processes with a certain command, or rather all processes with commands that match a certain pattern of text. It might be clearer for readers to change the wording accordingly.

    – David Z
    Jul 4 at 22:09

















3















I'm using the following code to kill all the PID's of a certain process, but its not working as expected.



pgrep -f <processname>

kill -9 $(pgrep -f <processname>)


when there are more than one PID, the above line throws error stating :




too many arguments.











share|improve this question
























  • What if you remove the -f? That exact same command (except for the -f) works for me in killing Chromium.

    – RonJohn
    Jul 4 at 20:41











  • A little nitpick: there's no such thing as "multiple process IDs of a single process". Each process has one PID. (Unless you count its threads, which I don't) What this question is about is killing all the processes with a certain command, or rather all processes with commands that match a certain pattern of text. It might be clearer for readers to change the wording accordingly.

    – David Z
    Jul 4 at 22:09













3












3








3








I'm using the following code to kill all the PID's of a certain process, but its not working as expected.



pgrep -f <processname>

kill -9 $(pgrep -f <processname>)


when there are more than one PID, the above line throws error stating :




too many arguments.











share|improve this question
















I'm using the following code to kill all the PID's of a certain process, but its not working as expected.



pgrep -f <processname>

kill -9 $(pgrep -f <processname>)


when there are more than one PID, the above line throws error stating :




too many arguments.








command-line bash grep kill






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 4 at 12:36









Yaron

9,4727 gold badges21 silver badges42 bronze badges




9,4727 gold badges21 silver badges42 bronze badges










asked Jul 4 at 11:56









Vignesh_AVignesh_A

184 bronze badges




184 bronze badges












  • What if you remove the -f? That exact same command (except for the -f) works for me in killing Chromium.

    – RonJohn
    Jul 4 at 20:41











  • A little nitpick: there's no such thing as "multiple process IDs of a single process". Each process has one PID. (Unless you count its threads, which I don't) What this question is about is killing all the processes with a certain command, or rather all processes with commands that match a certain pattern of text. It might be clearer for readers to change the wording accordingly.

    – David Z
    Jul 4 at 22:09

















  • What if you remove the -f? That exact same command (except for the -f) works for me in killing Chromium.

    – RonJohn
    Jul 4 at 20:41











  • A little nitpick: there's no such thing as "multiple process IDs of a single process". Each process has one PID. (Unless you count its threads, which I don't) What this question is about is killing all the processes with a certain command, or rather all processes with commands that match a certain pattern of text. It might be clearer for readers to change the wording accordingly.

    – David Z
    Jul 4 at 22:09
















What if you remove the -f? That exact same command (except for the -f) works for me in killing Chromium.

– RonJohn
Jul 4 at 20:41





What if you remove the -f? That exact same command (except for the -f) works for me in killing Chromium.

– RonJohn
Jul 4 at 20:41













A little nitpick: there's no such thing as "multiple process IDs of a single process". Each process has one PID. (Unless you count its threads, which I don't) What this question is about is killing all the processes with a certain command, or rather all processes with commands that match a certain pattern of text. It might be clearer for readers to change the wording accordingly.

– David Z
Jul 4 at 22:09





A little nitpick: there's no such thing as "multiple process IDs of a single process". Each process has one PID. (Unless you count its threads, which I don't) What this question is about is killing all the processes with a certain command, or rather all processes with commands that match a certain pattern of text. It might be clearer for readers to change the wording accordingly.

– David Z
Jul 4 at 22:09










2 Answers
2






active

oldest

votes


















5














killall <processname>


killall allows killing all processes by name or even regexes (-r) and a few other options for matching the correct group of processes. SIGTERM options are available (killall -9 name).






share|improve this answer






























    3














    That's what pkill is for:



    pkill -f <processname>


    Or, if you must use -9:



    pkill -9 -f <processname>



    In order to do what you were attempting, you would need to pass the output of the pgrep command to kill. Instead, you are passing a variable named $pgrep which, of course, has no value. You can see this by running the command after enabling set -x:



    $ set -x
    $ kill -9 $pgrep -f emacs
    + kill -9 -f emacs
    sh: kill: -f: arguments must be process or job IDs
    sh: kill: emacs: arguments must be process or job IDs


    (run set +x to disable debugging info)



    As you can see above, the $pgrep was removed since it is an undefined variable, and therefore empty, and the -f and emacs were passed as arguments to kill. What you wanted to do was use command substitution to pass the output of one command as input to another:



    kill $(pgrep -f emacs)


    Finally, avoid using kill -9 foo unless it is absolutely necessary and kill foo alone doesn't work. Using -9 can be quite destructive and doesn't let the process exit gracefully.






    share|improve this answer























    • I tried "pkill -f <processname>" and that was not working in my case. so I posted the question here. as per your suggestion using "pkill -9 -f <processname>" worked

      – Vignesh_A
      Jul 4 at 12:21













    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "89"
    ;
    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',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1155915%2fhow-to-delete-multiple-process-id-of-a-single-process%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    5














    killall <processname>


    killall allows killing all processes by name or even regexes (-r) and a few other options for matching the correct group of processes. SIGTERM options are available (killall -9 name).






    share|improve this answer



























      5














      killall <processname>


      killall allows killing all processes by name or even regexes (-r) and a few other options for matching the correct group of processes. SIGTERM options are available (killall -9 name).






      share|improve this answer

























        5












        5








        5







        killall <processname>


        killall allows killing all processes by name or even regexes (-r) and a few other options for matching the correct group of processes. SIGTERM options are available (killall -9 name).






        share|improve this answer













        killall <processname>


        killall allows killing all processes by name or even regexes (-r) and a few other options for matching the correct group of processes. SIGTERM options are available (killall -9 name).







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jul 4 at 13:00









        FiximanFiximan

        1,2495 silver badges13 bronze badges




        1,2495 silver badges13 bronze badges























            3














            That's what pkill is for:



            pkill -f <processname>


            Or, if you must use -9:



            pkill -9 -f <processname>



            In order to do what you were attempting, you would need to pass the output of the pgrep command to kill. Instead, you are passing a variable named $pgrep which, of course, has no value. You can see this by running the command after enabling set -x:



            $ set -x
            $ kill -9 $pgrep -f emacs
            + kill -9 -f emacs
            sh: kill: -f: arguments must be process or job IDs
            sh: kill: emacs: arguments must be process or job IDs


            (run set +x to disable debugging info)



            As you can see above, the $pgrep was removed since it is an undefined variable, and therefore empty, and the -f and emacs were passed as arguments to kill. What you wanted to do was use command substitution to pass the output of one command as input to another:



            kill $(pgrep -f emacs)


            Finally, avoid using kill -9 foo unless it is absolutely necessary and kill foo alone doesn't work. Using -9 can be quite destructive and doesn't let the process exit gracefully.






            share|improve this answer























            • I tried "pkill -f <processname>" and that was not working in my case. so I posted the question here. as per your suggestion using "pkill -9 -f <processname>" worked

              – Vignesh_A
              Jul 4 at 12:21















            3














            That's what pkill is for:



            pkill -f <processname>


            Or, if you must use -9:



            pkill -9 -f <processname>



            In order to do what you were attempting, you would need to pass the output of the pgrep command to kill. Instead, you are passing a variable named $pgrep which, of course, has no value. You can see this by running the command after enabling set -x:



            $ set -x
            $ kill -9 $pgrep -f emacs
            + kill -9 -f emacs
            sh: kill: -f: arguments must be process or job IDs
            sh: kill: emacs: arguments must be process or job IDs


            (run set +x to disable debugging info)



            As you can see above, the $pgrep was removed since it is an undefined variable, and therefore empty, and the -f and emacs were passed as arguments to kill. What you wanted to do was use command substitution to pass the output of one command as input to another:



            kill $(pgrep -f emacs)


            Finally, avoid using kill -9 foo unless it is absolutely necessary and kill foo alone doesn't work. Using -9 can be quite destructive and doesn't let the process exit gracefully.






            share|improve this answer























            • I tried "pkill -f <processname>" and that was not working in my case. so I posted the question here. as per your suggestion using "pkill -9 -f <processname>" worked

              – Vignesh_A
              Jul 4 at 12:21













            3












            3








            3







            That's what pkill is for:



            pkill -f <processname>


            Or, if you must use -9:



            pkill -9 -f <processname>



            In order to do what you were attempting, you would need to pass the output of the pgrep command to kill. Instead, you are passing a variable named $pgrep which, of course, has no value. You can see this by running the command after enabling set -x:



            $ set -x
            $ kill -9 $pgrep -f emacs
            + kill -9 -f emacs
            sh: kill: -f: arguments must be process or job IDs
            sh: kill: emacs: arguments must be process or job IDs


            (run set +x to disable debugging info)



            As you can see above, the $pgrep was removed since it is an undefined variable, and therefore empty, and the -f and emacs were passed as arguments to kill. What you wanted to do was use command substitution to pass the output of one command as input to another:



            kill $(pgrep -f emacs)


            Finally, avoid using kill -9 foo unless it is absolutely necessary and kill foo alone doesn't work. Using -9 can be quite destructive and doesn't let the process exit gracefully.






            share|improve this answer













            That's what pkill is for:



            pkill -f <processname>


            Or, if you must use -9:



            pkill -9 -f <processname>



            In order to do what you were attempting, you would need to pass the output of the pgrep command to kill. Instead, you are passing a variable named $pgrep which, of course, has no value. You can see this by running the command after enabling set -x:



            $ set -x
            $ kill -9 $pgrep -f emacs
            + kill -9 -f emacs
            sh: kill: -f: arguments must be process or job IDs
            sh: kill: emacs: arguments must be process or job IDs


            (run set +x to disable debugging info)



            As you can see above, the $pgrep was removed since it is an undefined variable, and therefore empty, and the -f and emacs were passed as arguments to kill. What you wanted to do was use command substitution to pass the output of one command as input to another:



            kill $(pgrep -f emacs)


            Finally, avoid using kill -9 foo unless it is absolutely necessary and kill foo alone doesn't work. Using -9 can be quite destructive and doesn't let the process exit gracefully.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jul 4 at 12:05









            terdonterdon

            71.8k13 gold badges148 silver badges232 bronze badges




            71.8k13 gold badges148 silver badges232 bronze badges












            • I tried "pkill -f <processname>" and that was not working in my case. so I posted the question here. as per your suggestion using "pkill -9 -f <processname>" worked

              – Vignesh_A
              Jul 4 at 12:21

















            • I tried "pkill -f <processname>" and that was not working in my case. so I posted the question here. as per your suggestion using "pkill -9 -f <processname>" worked

              – Vignesh_A
              Jul 4 at 12:21
















            I tried "pkill -f <processname>" and that was not working in my case. so I posted the question here. as per your suggestion using "pkill -9 -f <processname>" worked

            – Vignesh_A
            Jul 4 at 12:21





            I tried "pkill -f <processname>" and that was not working in my case. so I posted the question here. as per your suggestion using "pkill -9 -f <processname>" worked

            – Vignesh_A
            Jul 4 at 12:21

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Ask Ubuntu!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1155915%2fhow-to-delete-multiple-process-id-of-a-single-process%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

            Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

            Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?