Kill script kills too many processes?
Hello all,
English isnt my native language, so bear with me, I am trying to make this clear and short. User 1 and User 2 each start a mono process with sudo: "sudo mono user1.exe" "sudo mono user2.exe" Each user has a kill.sh in their directory, which is being called by user1.exe/user2.exe to kill the process. The script itself is ps aux | grep 'mono user1.exe' | awk ‘{print $1}’ | xargs kill which in theory should pull *only* the PID of "mono user1.exe" and kill only that. The problem: It kills any and every single instance of mono that is running on my system, every userx.exe thats open. I am confused, as a simple "ps aux | grep 'mono user1.exe'" does only return the mono user1.exe process and not the others. "ps aux | grep 'mono'" returns them all though. Any help on how I can modify that script so that it only kills the specific process? Would "pkill -9 -f 'mono MCuser1.exe'" work as well - or would it too kill every instance of mono? I cant do a lot more of trial and error, its not good I am killing those instances accidently... Thank you so much for your help! |
What about with awk call?
|
Quote:
How would I change the script? Thank you for helping! |
Hi, hope this will work
ps aux | grep 'mono' | grep 'user1.exe' | awk ‘{print $2}’ | xargs kill |
I don't see why the OP's first idea won't work, simply by changing the $1 to a $2 as shown by procfs above. The PID is the second field... Unless there's some different version of `ps` involved here.
|
I will try as soon as I have access again, in a few hours. I didnt expect help that quickly! If it works you are my personal hero, it feels like I spent so many hours on this already..
|
Another idea (for future reference), if this fails, is to give each individual user a symlink to the mono binary. That way, each user will show a unique process name for mono and you can kill based on that.
For example: user #1 has a symlink like /usr/bin/mono1 ---> /usr/bin/mono user #2 has a symlink like /usr/bin/mono2 ---> /usr/bin/mono user #3 has a symlink like /usr/bin/mono3 ---> /usr/bin/mono So it gives a unique executable name for each user. Finally, if none of this works, I'd be questioning if mono spawns instances of itself, basically keeping one top parent process off of which the individual ones are created, and so killing the wrong single process will kill them all. If still stuck, please show us the output of your `ps aux` command while more than one mono process is running. |
Why not kill with the following?
Code:
ps aux | sed 's/^ *//' | grep 'mono user1\.exe' | cut -d\ -f1 | xargs kill In fact your original command may work if you simply escape the period in your grep pattern. |
Post ps -aux output format, why don't try cut? Be aware of delimiters. What shell are you using? Be aware of delimiters. Eg. Bash always expands tabulators so cat foo | cut -f4 doesn't get expected results.
|
Thank you all once again for the input. I cant work on this till I get home, but I can access a web console for small things.
ps aux gives the following (removed all clutter) user1 18967 0.0 0.1 6064 1108 ? Ss 08:47 0:00 SCREEN user1 18968 0.0 0.1 6552 1868 pts/1 Ss 08:47 0:00 /bin/sh root 18969 0.0 0.1 5684 1128 pts/1 S+ 08:47 0:00 /bin/sh ./lifeline.sh root 18970 0.2 2.2 78928 23816 pts/1 Sl+ 08:47 0:52 mono user1.exe user2 19043 0.0 0.1 6064 1104 ? Ss 08:50 0:00 SCREEN user2 19044 0.0 0.1 6596 1980 pts/0 Ss 08:50 0:00 /bin/bash root 19048 0.0 0.1 5688 1128 pts/0 S+ 08:50 0:00 /bin/sh ./lifeline.sh root 19049 0.6 3.2 122032 34568 pts/0 Sl+ 08:50 2:13 mono user2.exe |
For me it seems that each mono user$.exe is a child of ./lifeline.sh script. My suspicions is that in fact you are killing ./lifeline.sh script which causes all their childs being killed as well.
|
Would a simple renaming of each of the users lifeline.sh scripts do the trick? I didnt think that this could be the reason...
|
I'd look at using ps -ux (the 'a' lists all processes -without it it should only list processes which belong to the user) or I'd use pgrep or even ps -U username ...
|
I don't know how ./lifeline.sh looks like - I thought that if a signal cannot be catched by a child it may go up and be catched by a parent. This may explain why ./lifline can be killed. You can always verify if ./lifeline runs after your killing command
ps -A | grep lifeline |
Quote:
|
What process create all sockets for ./lifeline scripts?
|
All times are GMT -5. The time now is 01:36 AM. |