Kill all process which uses specified port on Ubuntu 14.04 - node.js

What's the reason the process is still alive?
List of node process running and what I tried:
root#111:/home/ubuntu# ps -e -o pid,ppid,stat,cmd | grep node
3150 1 Ss sudo /usr/bin/node /home/ubuntu/chatapp/bin/www
3152 3150 Sl /usr/bin/node /home/ubuntu/chatapp/bin/www
4407 1558 S+ grep --color=auto node
root#111:/home/ubuntu# kill -9 3150
root#111:/home/ubuntu# kill -9 3152
root#111:/home/ubuntu# ps -e -o pid,ppid,stat,cmd | grep node
4665 1 Ss sudo /usr/bin/node /home/ubuntu/chatapp/bin/www
4667 4665 Sl /usr/bin/node /home/ubuntu/chatapp/bin/www
4680 1558 S+ grep --color=auto node

Try with:
$ sudo kill -9 18200
Note the added flag '-9', which forces the murder...
From linus signal(7) man page:
...
SIGKILL 9 Term Kill signal
...

You killed process id 18200
You state node is still running, but that's process id 31261, not the one you killed...
Is the remaining process (parent pid = 1) a child proces that's been orphaned by killing 18200?

Related

How can I get STAT column in ps command?

I installed Cygwin for 64 bit versions of Windows.and I run "Cygwin64 Terminal" in order to confirm whole process' state. As far as I know, ps command must show STAT column but It is impossible to find STAT column Whenever I execute "ps -l" or "ps aux" ,"ps -ef", "ps axj"..
I really want to view STAT column in ps command because a source code which I practice recently request me to check zombie process by means of ps command.
screenshot of ps command without STAT column
Use procps
$ /usr/bin/procps.exe ax
PID TTY STAT TIME COMMAND
1580 pty1 Ss 0:00 -bash
1624 pty0 R 0:00 /usr/bin/procps ax
1522 ? Ss 0:05 /usr/bin/mintty -i /Cygwin-Terminal.ico -
1599 pty1 T 0:00 less .bashrc
1523 pty0 Ss 0:00 -bash
1579 ? Ss 0:00 /usr/bin/mintty -i /Cygwin-Terminal.ico -
you can find it in procps-ng package
$ cygcheck -f /usr/bin/procps
procps-ng-3.3.16-1

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 stop a redis server that was started with --daemonize yes

I'm trying to kill a redis server that was started with --daemonize yes
I feel like this should be easy, but I am unable to successfully kill it based on standard methods. I'm using Redis 3.2 installed via these instructions: https://www.hugeserver.com/kb/install-redis-debian-ubuntu/
$ redis-server --daemonize yes
1550:C 13 Mar 05:54:55.436 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1550:C 13 Mar 05:54:55.437 # Redis version=4.0.8, bits=64, commit=00000000, modified=0, pid=1550, just started
1550:C 13 Mar 05:54:55.437 # Configuration loaded
$ kill 1550
-bash: kill: (1550) - No such process
$ kill -9 1550
-bash: kill: (1550) - No such process
$ killall redis-server
redis-server(1181): Operation not permitted
redis-server: no process found
$ /etc/init.d/redis-server stop
[....] Stopping redis-server (via systemctl): redis-server.service==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to stop 'redis-server.service'.
Authenticating as: Ubuntu (ubuntu)
Password:
Why should I need to enter a password to stop it? I never set a password when i started it. And why doesn't kill work? Even if I sudo it, it just restarts again after.
-------------------EDIT-------------------
Additional information. Using the kill command on the process ID doesn't work. I have to use sudo kill but then it comes back with another processid as if something restarts it. I just killed it 3 times and it's back again with a 4th processid –
---------- Solution thanks to #Kevin Law ----------
I needed to kill the daemonized service and then kill the process. Not just one or the other...
ubuntu#ip-MyIPAddress:~/Relayer$ ps -ef | grep redis-server
ubuntu 2381 1 0 18:39 ? 00:00:00 redis-server *:6379
ubuntu 2386 1358 0 18:39 pts/0 00:00:00 grep --color=auto redis-server
ubuntu#ip-MyIPAddress:~/Relayer$ sudo service redis-server stop
ubuntu#ip-MyIPAddress:~/Relayer$ ps -ef | grep redis-server
ubuntu 2381 1 0 18:39 ? 00:00:00 redis-server *:6379
ubuntu 2418 1358 0 18:39 pts/0 00:00:00 grep --color=auto redis-server
ubuntu#ip-MyIPAddress:~/Relayer$ kill 2381
ubuntu#ip-MyIPAddress:~/Relayer$ ps -ef | grep redis-server
ubuntu 2420 1358 0 18:39 pts/0 00:00:00 grep --color=auto redis-server
ubuntu#ip-MyIPAddress:~/Relayer$
There are three options for your question from my test.
Stop redis by stoping redis service. This is the recommend way in most cases.
sudo systemctl stop redis-server
or
sudo service redis-server stop
connect to this redis-server and shutdown it by redis-cli.
redis-cli
after connected to redis, issue shutdown to turn off redis-server
shutdown
Kill the redis-server process directly:
ps -ef | grep redis-server
kill -9 (pid)
Try following command to find the redis-server instances that are running and then try killing the exact instance with kill command.
ps -aef | grep redis

Process found by netstat is not listed in ps command and unable to be killed

I am running MINGW64 command line on Windows 7.
I want to find the process which occupies port 8082 by using 'netstat' and kill it. But an error occurs saying "No such process".
$ netstat -aon | grep 0.0.0.0:8082
TCP 0.0.0.0:8082 0.0.0.0:0 LISTENING 3960
$ kill -9 3960
bash: kill: (3960) - No such process
Then I run 'ps' command but can not find any process with pid 3960
$ ps -a
PID PPID PGID WINPID TTY UID STIME COMMAND
2716 1 2716 884 pty0 197108 09:53:42 /g/Apps/Java/jdk1.8.0_102/bin/java
4696 5248 4696 2740 pty2 197108 11:05:22 /usr/bin/bash
5248 1 5248 5248 ? 197108 11:05:22 /usr/bin/mintty
5256 4696 5256 4032 pty2 197108 11:16:33 /usr/bin/ps
Then try 'taskkill' command, but it is still not working and shows wired characters...
$ TASKKILL /PID /F 3960
▒▒▒▒: ▒▒Ч▒▒▒▒/ѡ▒▒ - 'C:/Program Files/Git/PID'▒▒
▒▒▒▒ "TASKKILL /?" ▒▒▒˽▒▒÷▒▒▒
I am confused and don't know how to kill such a non-existing process.

in linux - show a list of all processes and note if they are running or suspended

I'm new to linux.
How can I show a list of all processes that says about each process if it's running or suspended?
I've tried
ps -ef|grep myusername
but it doesn't say if the processes are running or not.
also tried
ps ux
same thing, it doesn't say if the processes are running or not.
I'm looking for something like this list:
I get this list when I move a process to background, I don't know how to see it otherwise...
You can use "ps" to list processes, This (ps aux) will list all the processes. Given an example output of it below.
ps aux | more
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 189160 9376 ? Ss 15:51 0:04 /usr/lib/systemd/systemd --switched-root --system --deserialize 20
root 2 0.0 0.0 0 0 ? S 15:51 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S 15:51 0:00 [ksoftirqd/0]
root 5 0.0 0.0 0 0 ? S< 15:51 0:00 [kworker/0:0H]
root 7 0.0 0.0 0 0 ? S 15:51 0:06 [rcu_sched]
root 8 0.0 0.0 0 0 ? S 15:51 0:00 [rcu_bh]
root 9 0.0 0.0 0 0 ? S 15:51 0:04 [rcuos/0]
By checking the STAT of the process ( UNDER "STAT" ) you can identify the process states, Below are some possible states codes.
R running or runnable (on run queue)
D uninterruptible sleep (usually IO)
S interruptible sleep (waiting for an event to complete)
Z defunct/zombie, terminated but not reaped by its parent
T stopped, either by a job control signal or because it is being
traced
You can type "man ps" to get more info.
You can use htop to see the list of processes and there is a column for process state
What does a C process status mean in htop?
http://www.howtogeek.com/howto/ubuntu/using-htop-to-monitor-system-processes-on-linux/
ps -p PID -o comm=
Enter the code above where PID is PID of the process.
Following command will be more helpful to you.
Use the command : sudo lsof -i -n -P
This command lists the Application Name, PID, User, IP version, Device ID and the Node with Port Name. It shows both TCP and UDP.
Variations :
To format it in a nice, readable way; use :
sudo lsof -i -n -P | more
To view view only TCP connections :
sudo lsof -i -n -P | grep TCP | more
To view view only UDP connections :
sudo lsof -i -n -P | grep UDP | more

Resources