how to terminate some process which is run with sudo with kill - kill

with an unprivileged user account, using bash, I could do:
sudo /bin/sleep 6000
and kill it with Ctrl-c. However, sending SIGINT or SIGKILL from another terminal won't work for that purpose.
Anyone knows why is that? I'd like to be able to kill the process sending a signal, for using in a script, for example.
Regards.

You're only allowed to send signals to a process running with the same UID (unless the sending process is running as root). When you use sudo, the new process is running as root, but if you try to kill it you're running as your normal userid. You would have to use sudo kill PID to kill it.
Signals sent from terminal control characters are treated specially: they can be sent to any process running in the same login session as the terminal.

Related

do not send hangup signal to background process when bash exit

I know when shell exits or itself receives SIGHUP, it will send SIGHUP to all background process.
'nohup cmd' or 'disown' will tell bash not to send SIGHUP. Is there a shell setting so that bash will always not send SIGHUP?
I want my backgroup process to run when bash got killed accidentally for various reasons.
Thanks.
Sounds like you might want to look into jobs and disown. https://www.gnu.org/software/bash/manual/html_node/Signals.html

How to Turn Off a Program Running from .bash_profile

I am working with a Raspberry Pi running linux, and have modified the .bash_profile file in order to a run a program I've made automatically upon login. This works great, but I was wondering how to turn the program off, since for ctrl+c I would need to be running the program in the terminal.
You can use Kill to terminate program by its process Id, Top command will list all the processes, You can also use Pkill, which will Terminate the process by its name.
-9 option forces process to shut down, so its very commonly used.
Example:
kill -9 "Process ID without Quotation marks"
pkill -9 "Name with Quotation marks (Case Sensitive)"
Check this.
I always use
pkill - f processname

How can I kill a Festival speech command?

Let's say I run the following command:
cat /var/log/dmesg | festival --tts
This might return the message [1] 4726, indicating a process ID associated with this operation. When I run kill 4726 or killall festival or killall cat or killall aplay, the speech does not stop (or, at least, it continues on for quite some time before stopping). If I run the command above, how can I kill what it starts doing?
Kill sends a SIGTERM to the program. SIGTERM tells the program to stop, allowing it to shut down gracefully. The program is unallocating memory, closing connections, flushing to disk, removing temp files, etc. So SIGTERM may not be immediate or quick.
Kill -9, sends a SIGSTOP or SIGKILL, which is only seen by the kernel. The kernel will terminate the process. While this is faster, it does not allow for a graceful exit.
I am not familiar with festival, so if you are worried that these commands are forking off processes and you want to stop all the children, you can brute force the issue by spawning them all out of a bash shell. When you kill the parent bash shell, it will kill all of the processes owned by it.
bash -c "cat /var/log/dmesg | festival --tts" &
You will get bash the pid for the bash shell, which you can kill and clean up all sub-procs.

bash & linux symbols, Jboss

I'm writing a script to start Jboss, load an application, send requests to the application, shutdown jboss and repeat. However I dont know how to shut Jboss down from the script. At the moment I'm using
pkill -9 java
But I dont think this is right, because it kills the process, not shut it down. Is there a way to shut it down similar to pressing CTRL-C?
You want a simple
pkill java
From the man page:
pkill will send the specified signal (by default SIGTERM) to each
process
SIGTERM will send a termination signal to the process. If the process is well-written, it will catch this signal and perform an orderly shutdown. If that fails, that's when you can use SIGKILL (-9) which is a forceable termination with no chance for the process to catch and perform cleanup.
Never use kill -9 <PID> by default. It breaks things up, like file descriptors and such.
Start to run kill <PID> alone, default is -15 signal.
See
man 7 signal
And In what order should I send signals to gracefully shutdown processes?
NOTE
kill or pkill doesn't change things so much, same signals are trigered
What you actually want is:
pkill -f jboss
using pkill java could kill any other processes using java on the box.

Kill all processes launched inside an xterm when exit

I'm using Cygwin to start some servers.
Each server is launched inside an xterm with a bunch of command like this one:
xterm -e $my_cmd /C &
Is there an easy way to kill all launched children (xterm and their running commands) in a row ?
I want also to be able kill a particular launched command when I close its parent xterm.
Someone knows how to perform that ?
killall xterm? That command is in the psmisc package. Xterm will notify its child process with a SIGHUP ("hangup") before it exits. Normally that will cause the child process to exit too, although some servers interpret that signal differently.

Resources