cygwin kill background process - cygwin

I can see a process with ps, but it does not appear in "tasklist" (or windows taskmanager).
PID PPID PGID WINPID TTY UID STIME COMMAND
15356 1 16284 10496 pty2 1001 12:59:42 /cygdrive/c/Users/Application1
I openned terminal as Administrator. I have tried using PID, WINPID and PGID as xxxx in:
kill -9 xxxx
/bin/kill -f xxxx
taskkill /pid xxxx
None of them work.

ppid 1, seems to be a child process of something. in the worst case kill the "father"-process.
Is your taskmanger started as Admin? view of all user processes activated?
Did you try to kill it with alternative taskmanagers like "task explorer"?

I got rid of this problem simply by restart Cygwin. The process went away after restart.

You can use the WINPID. Go into Windows Task Manager (Win 8.1), go to the "Details" tab (older versions of Windows show PID on the process tab or may require you to enable displaying it in options). You will see the PID for each process. Find the one matching the WINPID and kill it.
FYI, the PPID is the parent process. 1 means that the parent is gone (the instance of Cygwin that you closed). Depending on how the command was invoked, sometimes it'll stick around in the background even after the parent goes away. Just because the Cygwin window was closed, doesn't mean that the processes it started were stopped. I found this to be the case when piping output and one of the commands in the pipe chain locked up.

Related

Ubuntu: Is there any difference of killing a child process when the child process runs in the foreground or background?

Open a terminal
Open the second terminal
Excute command "$ xlogo" in the sceond terminal
Find out the parent process of xlogo in the first terminal
(I find out that "bash" is the parent process)
Terminate the parent process of xlogo in the first terminal
(Command:$ kill -9 PID of parent process)
At this moment, "xlogo" and the second terminal are gone.
Open the third terminal.
Excute the command "$ xlogo &" in the third terminal (Let xlogo running in the background)
Teminate the parent process of xlogo in the first
terminal
(Command:$ kill -9 PID of parent process)
At this moment, "xlogo" still alive, but the third terminal is gone.
By excuting the command "$ pstree", I find that "xlogo" belongs to "systemd".
Questions:
a) Why "xlogo" was killed with its parent process when "xlogo" ran in the foreground?
b) Why "xlogo" still alive and didn't die with its parent process when "xlogo" ran in the background?
I am searching for a long time on the net. But get nothing.
Could anyone try to give some ideas on how to explain this?
thx

How to make killall close the terminal that the process is in?

So how can I close the terminal where the process is in with killall.
I have tried this:
In 1st terminal:
killall node
In 2nd terminal:
Ready
Terminated
But I want only the 2nd terminal to close after the node is killed.
You can use the -t option:
killall -t $(tty)
will call all processes started from the terminal session (even with nohup), including the shell. So, your terminal will get closed.
You need to also kill the process which runs the terminal, which is usually the parent process of the node process.
The question How do I get the parent process ID of a given child process? is a good place to start. You can find the PIDs of the node processes via How to find the Process ID of a running terminal program.

How to kill a process by its pid in linux

I'm new in linux and I'm building a program that receives the name of a process, gets its PID (i have no problem with that part) and then pass the PID to the kill command but its not working. It goes something like this:
read -p "Process to kill: " proceso
proid= pidof $proceso
echo "$proid"
kill $proid
Can someone tell me why it isn't killing it ? I know that there are some other ways to do it, even with the PID, but none of them seems to work for me. I believe it's some kind of problem with the Bash language (which I just started learning).
Instead of this:
proid= pidof $proceso
You probably meant this:
proid=$(pidof $proceso)
Even so,
the program might not get killed.
By default, kill PID sends the TERM signal to the specified process,
giving it a chance to shut down in an orderly manner,
for example clean up resources it's using.
The strongest signal to send a process to kill without graceful cleanup is KILL, using kill -KILL PID or kill -9 PID.
I believe it's some kind of problem with the bash language (which I just started learning).
The original line you posted, proid= pidof $proceso should raise an error,
and Bash would print an error message about it.
Debugging problems starts by reading and understanding the error messages the software is trying to tell you.
kill expects you to tell it **how to kill*, so there must be 64 different ways to kill your process :) They have names and numbers. The most lethal is -9. Some interesting ones include:
SIGKILL - The SIGKILL (also -9) signal forces the process to stop executing immediately. The program cannot ignore this signal. This process does not get to clean-up either.
SIGHUP - The SIGHUP signal disconnects a process from the parent process. This an also be used to restart processes. For example, "killall -SIGUP compiz" will restart Compiz. This is useful for daemons with memory leaks.
SIGINT - This signal is the same as pressing ctrl-c. On some systems, "delete" + "break" sends the same signal to the process. The process is interrupted and stopped. However, the process can ignore this signal.
SIGQUIT - This is like SIGINT with the ability to make the process produce a core dump.
use the following command to display the port and PID of the process:
sudo netstat -plten
AND THEN
kill -9 PID
Here is an example to kill a process running on port 8283 and has PID=25334
You have to send the SIGKILL flag with the kill statement.
kill -9 [pid]
If you don't the operating system will choose to kill the process at its convenience, SIGKILL (-9) will tell the os to kill the process NOW without ignoring the command until later.
Try this
kill -9
It will kill any process with PID given in brackets
Try "kill -9 $proid" or "kill -SIGKILL $proid" commands. If you want more information, click.
Based on what you have there, it looks like you aren't getting the actual PID in your proid variable. If you want to capture the output of pidof, you will need to enclose that command in backtics for the old form of command substitution ...
proid=`pidof $proceso`
... or like so for the new form of command substitution.
proid=$(pidof $proceso)
I had a similar problem, only wanting to run monitor (Video surveillance) for several hours a day.
Wrote two sh scripts;
cat startmotion.sh
#!/bin/sh
motion -c /home/username/.config/motion/motion.conf
And the second;
cat killmotion.sh
#!/bin/sh
OA=$(cat /var/run/motion/motion.pid)
kill -9 $OA
These were called from crontab at the scheduled time
ctontab -e
0 15 * * * /home/username/startmotion.sh
0 17 * * * /home/username/killmotion.sh
Very simple, but that's all I needed.

Linux killing process with kill -9 PID

Tried with some examples like ps and ps -ef,after killing a process by using kill-9 PID in Linux,how to verify weather the process is killed or not?
Just run ps aux stat,pid again, and you will see the process with this pid is either a zombie ('Z' in the first column) or dead.
Edit:
Thanks, Mark B, for pointing me about zombies.
Ater the kill, check the PID of the process:
$ pidof PROCESS
You should see no output if the process is gone.
Another similar way:
$ ps aux | grep PROCESS
Notes:
You can kill your own process, but only root user can kill system process or another user process.
After you KILL the process you can get a zombie, you can still see it in the process list but with process STATE Z (wich means Zombie). Zombies cant be killed, they are already dead, so to "kill" zombies you need to kill the zombie's parents. That said, in general you don’t need to get rid of zombie processes unless you have a large amount of them.

How to terminate screen while running a .sh?

I search everyplace but didn't find a solution to my question, please help!
My situation:
I need run a huge .sh in my AWS (amazon web service), it will take about 4-5 hours to finish the job, I don't want to sit down just look those logs, so I create a screen to run it (screen 1), but while I configure the installation, I make a stupid mistake to create another screen and config and execute (screen 2).
The question is:
Screen 2 finish the job and I 'exit' the screen(terminated), but I can't terminate screen 1, because when I enter 'exit', it become a parameter of configuration, CTRL+A+K also din't work, please tell me how can I kill this screen, thanks.
KILL -9 <pid> does the trick. If you want it to run in the background do it for the parent process.
logon to another session.
ps -ef | grep yourusername
will show you the processes running that you own. The leftmost number is the pid of the process.
Issue a kill command on the process you want to stop.
kill [pid]
If that fails try
kill -9 [pid]

Resources