I want to kill a process of xterm that is run by hacker with my login name.
So, I write a shell script to do my goal.
I run 2 xterm and then I run my script on a first xterm. it should kill the process of a second xterm but it doesn't.Why?
Here is my code :
my process id is a string so it cannot kill by this command "kill -9 processid"?
Another thing that might trip you up is using cut. You are assuming that there are always two blanks between the user name and the process id. In the case where the PID is shorter than 5 digits then there will be more leading blanks, and the cut command will not pick up the right information. (I checked ps output from both a Linux and FreeBSD system and neither left justify the PID.) If I were writing the script, I'd do something like this:
which will generate a list of process IDs regardless of the number of blanks that separate the user name from the PID.
You're going to have the same problem with the other cut command:
For the times that it fails, there are probably enough extra blanks in the line that picking up 'field 10' isn't getting the tty, but some other string. Then when you compare these to your tty name they will never match and you'll kill your session. Use the same technique with awk to pick up the correct tty field from the ps output.
If you want to be doubly sure that you don't kill your xterm, you could pass the process id to the script (it's possible to have the script dig this info out, but easier to pass it in). If your script is called kill_hacker, the command line might look something like:
and the code in the script could be changed to test that the process id you're about to kill isn't the one passed in:
With this you could also elminate the need to get the tty information from the ps output.
You're going to have the same problem with the other cut command:
For the times that it fails, there are probably enough extra blanks in the line that picking up 'field 10' isn't getting the tty, but some other string. Then when you compare these to your tty name they will never match and you'll kill your session. Use the same technique with awk to pick up the correct tty field from the ps output.
If you want to be doubly sure that you don't kill your xterm, you could pass the process id to the script (it's possible to have the script dig this info out, but easier to pass it in). If your script is called kill_hacker, the command line might look something like:
and the code in the script could be changed to test that the process id you're about to kill isn't the one passed in:
With this you could also elminate the need to get the tty information from the ps output.
Hi guys i have a problem with a script... this script creates differents GUI with YAD... well i want that when i press the "Cancel" button on this graphical interface all the child process and even the same script should be killed
#!/bin/bash
function gui_start {
local choice=""
... (4 Replies)
What I need to learn is how to use a script that launches background processes, and then kills those processes as needed.
The script successfully launches the script. But how do I check to see if the job exists before I kill it?
I know my problem is mostly failure to understand parameter... (4 Replies)
Hello all... new to these forums and a bit of a newbie with linux aswell.
I need to figure out how to write a shell script to kill a process by name as given to the script as an argument. I've got that part working OK, but i need to make sure that the script does not allow processes that are... (6 Replies)
Hi Experts, we do have a shell script for Unix Solaris, which will kill all the process manullay, it used to work in my previous env, but now it is throwing this error.. could some one please help me to resolve it
This is how we execute the script (and this is the requirement) ... (2 Replies)
hello Bros,
I need to write some script that i can put it on crontab which checks for a process X if running. If the process X is ruuning then take the PID and kill it or display message that says process X is not running.
I am using AIX 5.3
Thanks guys.:b: (2 Replies)
Hello guys,
I have a process named monitoreo, with 'monitoreo start' my process start until i kill them, now i want to do 'monitoreo stop' to kill them.
After 'monitoreo start' i have this process running:
ps -af
UID PID PPID C STIME TTY TIME CMD
ati 10958 1495 ... (5 Replies)