Using Python to terminate a process results in a "Permission denied" error

Currently, I have a python script set up to manage the tcpdump tool. The issue arises when attempting to terminate the tcpdump process within my python script:

import subprocess
pid = 9669  # pid of the tcpdump process
subprocess.call(["sudo", "kill", "-9", f"{pid}"])

An error is triggered displaying:

kill: (9669): Permission denied

Strangely enough, if I directly input sudo kill -9 9669 in the terminal, it successfully terminates the process without any hitch. It's worth noting that on this system, no password is required for commands like sudo tcpdump or sudo kill. Both the subprocess.call method and manual terminal command should theoretically yield the same result, yet only one functions as intended. Where am I going wrong?

Answer №1

After initially installing PyCharm via snap, I found that it was being restricted by AppArmor. To resolve this issue, I uninstalled PyCharm through snap, downloaded the PyCharm tar file, and manually installed it. Now, my tcpdump stopping script functions correctly within PyCharm.

I must admit, it is quite puzzling to confine a developer tool in a sandbox environment where certain functionalities are limited due to the constraints of the sandbox itself.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing Blender Python scripting to ensure seamless user interface functionality during extensive computational processes

Currently, I am engaged in scripting with Blender to handle multiple objects simultaneously. However, whenever I run my script, it causes the user interface to freeze while executing its tasks. I am seeking a way to prevent this issue so that I can monitor ...

When attempting to open Google using Selenium, the error "Unable to access dead object: malformed URL" is displayed

I am currently working on a complex test case using Python Selenium. In the middle of the process, which involves loading pages with nested iframes, I encountered an issue when trying to open a webpage: driver.get("https://www.google.com") Unfortunately, ...

Issue: TemplateNotFound when accessing /app/index.html

Having trouble resolving this error message despite trying various solutions. Whenever I start the server, I encounter the following error: TemplateDoesNotExist at /app/index.html Here is a snapshot of my app structure In the 'settings.py' file ...

What is the procedure for swapping out a value/phrase in a column within a data frame?

Looking to update specific strings in a column within a data frame, which currently appears as: df["column"] ------------------ 1. Ne Road 2. Rosemarys street se 3. Plunkett pkwy 4. and so on..... There are thousands of values like these that nee ...

Comparing the columns of a numpy matrix with an array and analyzing their

I'm working with a numpy matrix and looking to compare each column to a specified array, for example: M = np.array([1,2,3,3,2,1,1,3,2]).reshape((3,3)).T v = np.array([1,2,3]) Now my goal is to compare every column of M with v. In other words, I want ...

Error message "AttributeError" occurs specifically during the second iteration of a for loop

I am currently working on a project where I need to iterate through a CSV file containing links and perform web scraping using those links. The program works perfectly fine during the first iteration of the for loop. However, when it comes to the second it ...

Unable to transfer a bulky Excel document with Openpyxl

In a dilemma with a 9000 row x 30 column Excel file that needs to be transferred from one Excel workbook to another. The challenge arises when the code never seems to stop running, consuming a significant portion of my laptop's memory (screenshot). I ...

Python - Evaluating a Value with Several Variables

Could someone lend a hand in creating this flowchart using Python? I'm struggling to make the program evaluate a variable against a condition and then determine its next step. It's those numerous if-else statements that are causing difficulties f ...

Is it possible to utilize Python to examine the values in a dataframe's column and add a new value to another column depending on the outcome?

I have a CSV file containing a column filled with various values such as... Column A Hi [First]! Thank You! What Car? Are you [First] [Last]? Did you know? Save 25% [First]! Get $2,000 Back! Embrace the road ahead Everyone saves 30% ...

Concurrent Python - simultaneously instantiate objects within a separate class

I'm facing a challenge with Parallel Python where I want to create an object from a custom class inside another method from a different class used for parallel processing. Here is a simplified version of what I am attempting to achieve: import pp cl ...

Steps for removing a line in a docx file using python-docx

I am dealing with a Docx file that only consists of text, and I am looking to make modifications to it using python-docx. My goal is to eliminate any empty lines as well as lines that feature a specific style. This is the approach I have taken so far: im ...

Guide on saving the output of a convolutional layer in Tensor Flow to a file or printing it

Snippet of Code: conv2 = conv2d(conv1, weights['wc2'], biases['bc2']) # Perform Max Pooling (down-sampling) conv2 = maxpool2d(conv2, k=2) with tf.Session() as sess: print(sess.run(conv2)) Despite implementing the above code, I ...

Selenium is unable to identify a clickable button in this scenario

<html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Unique Phantom Wallet Title</title> <style> @font-face { font-family: Ci ...

Python Selenium WebDriver - Struggling to find any element on the webpage

I am currently struggling to navigate through a particular webpage (). My goal is to choose options from the dropdown menu and then proceed by clicking on the name of each country to be directed to a different webpage. Despite my efforts, I have faced dif ...

Newbie OOP Project Seeking Constructive Criticism

Hello everyone, I have just completed the development of a very basic airline reservation system and would greatly appreciate your feedback. Please share your thoughts on whether I am over-complicating information, passing parameters where unnecessary, or ...

Leveraging functions within a class

I created a custom class to handle string manipulations in Python: class bstring(str): words2numbers = { '1' : 'one ', '2' : 'two ', '3' : 'three ', '4' : 'four ...

The panel is not aligned correctly and has an incorrect aspect ratio in the mplfinance plot

I need help with plotting a subplot, as I am encountering two issues. #1 The setting for panel_ratio is not being recognized when set to (6,1). #2 The y axis of the top panel extends too far down and overlaps with the y axis of the bottom panel, caus ...

Text on a page is elusive for Webdriver

Looking to extract the synopsis of a movie from this page: I have encountered an issue where when running this code in a loop, it occasionally misses fetching the description for certain movies. However, if I remove the loop and manually visit the same UR ...

How to print a webpage using selenium automation technology

Is there a way to use Selenium to automate going to a webpage, setting the printing properties to generate a colored PDF, and saving it in the same directory as where my Python file is located? When I press ctrl P, it only gives me options like choosing th ...

Getting data from non-input fields in Flask

Seeking some guidance here - struggling to figure out how to extract values from elements other than input fields using Python with Flask. For instance, I'm working with an HTML form containing the following elements: <form action="/newgame" metho ...