<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rick Dumpleton</title>
    <description>The latest articles on DEV Community by Rick Dumpleton (@rickduk).</description>
    <link>https://dev.to/rickduk</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1030116%2F20370499-2e83-4bf7-a591-d4f9bc1a48a9.png</url>
      <title>DEV Community: Rick Dumpleton</title>
      <link>https://dev.to/rickduk</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rickduk"/>
    <language>en</language>
    <item>
      <title>Kill Stubborn Processes By Name</title>
      <dc:creator>Rick Dumpleton</dc:creator>
      <pubDate>Wed, 06 Sep 2023 04:33:38 +0000</pubDate>
      <link>https://dev.to/rickduk/kill-stubborn-processes-by-name-1imk</link>
      <guid>https://dev.to/rickduk/kill-stubborn-processes-by-name-1imk</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import os
import signal

# Function to find processes with a partial name and attempt to kill them
def find_and_kill_processes(partial_name):
    # Use pgrep to find all PIDs with a partial process name match
    pid_list = os.popen(f'pgrep -f "{partial_name}"').read().split()

    # Check if any matching processes were found
    if not pid_list:
        print(f"No processes found matching: {partial_name}")
    else:
        print(f"Processes found matching: {partial_name}")
        for pid in pid_list:
            print(f"PID: {pid}")

        # Ask for confirmation to kill the processes
        confirm = input("Do you want to kill these processes? (y/n): ").strip().lower()
        if confirm == 'y':
            for pid in pid_list:
                try:
                    # First attempt to terminate the process with SIGTERM (less forceful)
                    os.kill(int(pid), signal.SIGTERM)
                    print(f"Terminating process with PID {pid} using SIGTERM")
                except ProcessLookupError:
                    print(f"Process with PID {pid} not found.")
                except PermissionError:
                    print(f"Permission denied to terminate process with PID {pid}. Trying SIGKILL...")
                    try:
                        # If SIGTERM fails, try SIGKILL (more forceful)
                        os.kill(int(pid), signal.SIGKILL)
                        print(f"Forcibly killing process with PID {pid} using SIGKILL")
                    except ProcessLookupError:
                        print(f"Process with PID {pid} not found.")
            print("Processes terminated.")
        else:
            print("Operation canceled.")

# Get user input for the partial process name
partial_name = input("Enter a partial process name to find and kill: ").strip()

# Call the function to find and potentially kill matching processes
find_and_kill_processes(partial_name)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
  </channel>
</rss>
