Different PID for the same process - linux

I am just trying to understand more about the PID column when running the ps command.
If I have two terminal windows open, in the first one I run the following command
firefox &
Then run the ps command in BOTH and get the following output from the first window
PID TTY TIME CMD
16814 pts/1 00:00:00 bash
16822 pts/1 00:00:04 MainThread
16881 pts/1 00:00:02 Privileged Cont
16938 pts/1 00:00:00 WebExtensions
17026 pts/1 00:00:00 Web Content
17081 pts/1 00:00:00 ps
And the following in the second
PID TTY TIME CMD
16794 pts/0 00:00:00 bash
17082 pts/0 00:00:00 ps
In both outputs we see the shell process. Why do they not have the same PID, even if it has the same process name.

Related

Programmatically close the Browser from Linux Terminal in Chrome OS?

I am trying to write a bash script that will automate some activity in the Browser on my Chromebook, and part of the workflow involves closing the Browser. I can't for the life of me figure out how to accomplish this.
pkill -9 [PID] doesn't work -- the Chrome Browser doesn't show up when listed, and it can't even be killed from task manager.
Any ideas?
The argument to pkill is not a PID.
"pkill chrome" would work.
$ /usr/bin/google-chrome-stable &
[1] 11653
$
$ ps
PID TTY TIME CMD
264 pts/1 00:00:00 bash
11879 pts/1 00:00:04 chrome
11883 pts/1 00:00:00 cat
11884 pts/1 00:00:00 cat
11894 pts/1 00:00:00 chrome
11895 pts/1 00:00:00 chrome
11897 pts/1 00:00:00 nacl_helper
11900 pts/1 00:00:00 chrome
11919 pts/1 00:00:01 chrome
11921 pts/1 00:00:00 chrome
11922 pts/1 00:00:00 chrome
11936 pts/1 00:00:00 chrome
11944 pts/1 00:00:00 chrome
11945 pts/1 00:00:01 chrome
12067 pts/1 00:00:00 chrome
12097 pts/1 00:00:00 ps
$
$ pkill chrome
$
[1]+ Done /usr/bin/google-chrome-stable
$ ps
PID TTY TIME CMD
264 pts/1 00:00:00 bash
12100 pts/1 00:00:00 ps
$

Manual fsck stuck and no progress during disk check

I wanted to run an fsck check on my 5TB external hard drive on my raspberry pi.
This is the output:
$ sudo e2fsck -c -v /dev/sda
e2fsck 1.44.5 (15-Dec-2018)
Checking for bad blocks (read-only test): 0.46% done, 5:04 elapsed. (0/0/0 errors)
There has been zero progress for hours now. The elapsed time is stuck as well. This is actually my second attempt. Before I tried sudo e2fsck -p -c -v /dev/sda. This one doesn't give any output, that's why I let it run for a whole week before terminating.
My drive is unmounted, partitionless, and freshly formatted with mkfs.ext4. Output from ps:
$ ps -a
PID TTY TIME CMD
1075 tty1 00:00:00 bash
8404 pts/1 00:00:00 sudo
8405 pts/1 00:00:04 e2fsck
8446 pts/1 00:00:00 sh
8447 pts/1 00:00:05 badblocks
23605 pts/2 00:00:00 ps
I noticed on my first attempt, that it was impossible to send a SIGINT, SIGTERM, or SIGKILL to badblocks.
Why is this?

Change process title/name in bash script

There is a field in process object in node.js: process.title
That field allows you to change process name displayed in top or ps command on linux.
Is there some way to do this for and in bash script also?
Changing the command line reference from running processes is possible on *NIX with /proc filesystem :
$ ps
PID TTY TIME CMD
106 tty4 00:00:01 bash
719 tty4 00:00:00 ps
$ echo "toto" > /proc/106/comm
$ ps
PID TTY TIME CMD
106 tty4 00:00:01 toto
719 tty4 00:00:00 ps
$
And yes, it's not the prettiest way to do so.

Killing subprocess from inside a Docker container kills the entire container

On my Windows machine, I started a Docker container from docker compose. My entrypoint is a Go filewatcher that runs a task of a taskmanager on every filechange. The executed task builds and runs the Go program.
But before I can build and run the program again after filechanges I have to kill the previous running version. But every time I kill the app process, the container is also gone.
The goal is to kill only the svc1 process with PID 74 in this example. I tried pkill -9 svc1 and kill $(pgrep svc1). But every time the parent processes are killed too.
The commandline output from inside the container:
root#bf073c39e6a2:/app/cmd/svc1# ps -aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 2.5 0.0 104812 2940 ? Ssl 13:38 0:00 /go/bin/watcher
root 13 0.0 0.0 294316 7576 ? Sl 13:38 0:00 /go/bin/task de
root 74 0.0 0.0 219284 4908 ? Sl 13:38 0:00 /svc1
root 82 0.2 0.0 18184 3160 pts/0 Ss 13:38 0:00 /bin/bash
root 87 0.0 0.0 36632 2824 pts/0 R+ 13:38 0:00 ps -aux
root#bf073c39e6a2:/app/cmd/svc1# ps -afx
PID TTY STAT TIME COMMAND
82 pts/0 Ss 0:00 /bin/bash
88 pts/0 R+ 0:00 \_ ps -afx
1 ? Ssl 0:01 /go/bin/watcher -cmd /go/bin/task dev -startcmd
13 ? Sl 0:00 /go/bin/task dev
74 ? Sl 0:00 \_ /svc1
root#bf073c39e6a2:/app/cmd/svc1# pkill -9 svc1
root#bf073c39e6a2:/app/cmd/svc1
Switching to the containerlog:
task: Failed to run task "dev": exit status 255
2019/08/16 14:20:21 exit status 1
"dev" is the name of the task in the taskmanger.
The Dockerfile:
FROM golang:stretch
RUN go get -u -v github.com/radovskyb/watcher/... \
&& go get -u -v github.com/go-task/task/cmd/task
WORKDIR /app
COPY ./Taskfile.yml ./Taskfile.yml
ENTRYPOINT ["/go/bin/watcher", "-cmd", "/go/bin/task dev", "-startcmd"]
I expect only the process with the target PID is killed and not the parent process that spawned it it.
You can use process manager like "supervisord" and configure it to re-execute your script or the command even if you killed it's process which will keep your container up and running.

How to see a terminal output from a previously closed terminal

I connect to a remote server using SSH
I was compiling using cmake and then make, it's not common to have a progress percentage in compilation process, but this time it has. I was watching the compilation process until my internet connection failed, so puTTY closed the session and I had to connect again to my server. I though that all the progress was lost, but i first make sure by watching the processes list by ps aux command, and I noticed that the processes related to the compilation are still running:
1160 tty1 Ss+ 0:00 /sbin/mingetty tty1
2265 ? Ss 0:00 sshd: root#pts/1
2269 pts/1 Ss 0:00 -bash
2353 pts/1 S+ 0:00 make
2356 pts/1 S+ 0:00 make -f CMakeFiles/Makefile2 all
2952 ? S 0:00 pickup -l -t fifo -u
3085 ? Ss 0:00 sshd: root#pts/0
3089 pts/0 Ss 0:00 -bash
3500 pts/1 S+ 0:01 make -f src/compiler/CMakeFiles/hphp_analysis.dir/bui
3509 pts/1 S+ 0:00 /bin/sh -c cd /root/hiphop/hiphop-php/src/compiler &&
3510 pts/1 S+ 0:00 /usr/bin/g++44 -DNO_JEMALLOC=1 -DNO_TCMALLOC=1 -D_GNU
3511 pts/1 R+ 0:03 /usr/libexec/gcc/x86_64-redhat-linux6E/4.4.4/cc1plus
3512 pts/0 R+ 0:00 ps ax
I would like to know if is possible to watch the current progress of the compilation by watching the previously closed terminal output. Something similar like 'cat /dev/vcsa1' or something
As per the comment above, you should have used screen.
As it is, you could try to peek at the file descriptors used by sshd and the shell that you started, but I don't think this will get you very far.

Resources