Sample Header Ad - 728x90

Process appears with square brackets ([]) around name after being SIGKILL'd

2 votes
1 answer
547 views
I am executing and killing a process as follows:
python some_script.py &; pid=$!; sleep 5; kill -9 $!; ps -o pid,sid,uid,state,start,command
In other words: I execute a script in the background, record its process id, sleep 5 seconds, terminate it with a SIGKILL, and finally display the list of processes. The script itself is quite memory intensive. Its source code is included at the end of the question. The output of ps is
PID    SID      UID S  STARTED COMMAND
 72014  73317 22563342 R 20:56:36 [python]
This is followed by confirmation that the process was successfully killed:
+ killed     python some_script.py
My question: **why is the Python process displayed with brackets around its name in ps?** According to [this answer](https://unix.stackexchange.com/questions/22121/what-do-the-brackets-around-processes-mean) , square brackets indicate that the process's arguments are unavailable. Usually because the process in question is a kernel process, although clearly that isn't the case here. One possibility that I can think of is that the process's memory has been wiped, including its stack, which contains the list of arguments. But if the process's memory is being wiped by the kernel, shouldn't its state be DYING or ZOMBIE instead of RUNNING? --- Source code for some_script.py: ```[python] import asyncio async def create_tasks(n_tasks): tasks = [task() for _ in range(n_tasks)] await asyncio.gather(*tasks) async def task(): await asyncio.sleep(10) if __name__ == "__main__": asyncio.run(create_tasks(1000000))
Asked by Alessandro Power (305 rep)
Nov 19, 2023, 09:09 PM
Last activity: Nov 20, 2023, 05:56 AM