Why is pid changed in different terminal session?
0
votes
1
answer
52
views
I use WSL2 and was trying to use gdb to debug a c code following this gdb cheatsheet.
In summary it shows a way to call a python code solve.py that calls a c code, and displays the pid of itself.
And in another terminal session, I run gdb to communicate with the solve.py process by specifying the pid of solve.py.
However I realized I was failing to communicate with solve.py because the process pid was wrong. I ran ps and found out the solve.py was slightly different with what I saw in the first terminal. Can anyone explain why?
Below is a demonstration.
(env) junha@DESKTOP-3B9ANKQ:~/cs2107$ python3 solve.py
[+] Starting local process './test': pid 627
[*] Paused (press any to continue)
then I am supposed to run
gdb -p 627
as given in the cheatsheet.
But it doesn't work, and when I use
ps a
, I see that the actually pid is 624 not 627.
junha@DESKTOP-3B9ANKQ:~$ ps a
PID TTY STAT TIME COMMAND
226 hvc0 Ss+ 0:00 /sbin/agetty -o -p -- \u --noclear --keep-baud - 115200,38400,9600 vt220
231 tty1 Ss+ 0:00 /sbin/agetty -o -p -- \u --noclear - linux
388 pts/0 Ss 0:00 -bash
389 pts/1 Ss 0:00 /bin/login -f
508 pts/1 S+ 0:00 -bash
573 pts/2 Ss 0:00 -bash
624 pts/0 S+ 0:00 python3 solve.py
627 pts/3 Ss+ 0:00 ./test
629 pts/2 R+ 0:00 ps a
and below works:
gdb -p 624
Asked by B1LLP4RK
(29 rep)
Nov 16, 2024, 10:35 AM
Last activity: Nov 16, 2024, 03:45 PM
Last activity: Nov 16, 2024, 03:45 PM