Operating System - HP-UX
1830938 Members
1946 Online
110017 Solutions
New Discussion

help with ksh fuser kill script

 
SOLVED
Go to solution
Stuart Abramson_2
Honored Contributor

help with ksh fuser kill script

Our nightly BCV scripts unmount file systems so that we can synch them to the STDs.
#
Occasionally they fail because the file system is busy. We have an "fuser -kcu" section that kills processes in the script, but I want to know the name of the process involved (because it should already be gone).
#
Can someone help me get it out of this file, please?
#
fuser -kcu $DIR 1>file1 2>file2
#
"file1" looks like this. It could have one entry in one line or 40 entries in 4 lines. It fills a line with PIDs and then moves to the next line. There are a variable number of spaces between PIDs, depending on the length of the PID, and how many fill a line. (There are 4 spaces between PIDs in this example. The ITRC Forum web page condenses spaces.) I can't figure out how to get a single PID in a variable all by itself one at a time:
#
# cat file1
#
13751 14052 14061 13735 13898 13742 13747 13745 13755 13836 13731 13737 13765 13775 14042 13767 13769 13771 13773 13779 13777 13847 13855 13856 13859 13861 13870 13871 13890 13886 13888 13901 14056 13740
7 REPLIES 7
Elmar P. Kolkman
Honored Contributor
Solution

Re: help with ksh fuser kill script

This should do the trick:

for pid in $(cat file1)
do
ps -fp $pid
done
Every problem has at least one solution. Only some solutions are harder to find.
Kent Ostby
Honored Contributor

Re: help with ksh fuser kill script

The problem is that you will have already killed the processes by the time you go to run the ps command.

I would suggest that you run "fuser -cu $DIR 1> file1 2> file2" (without the kill) first .

Then use the suggested loop in the last response.

Then redo your current fuser command.

Or

do the fuser without kill then do the ps script, but after the ps and before the done add : kill -SIGKILL $pid

Best regards,

Kent M. Ostby

"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
Stuart Abramson_2
Honored Contributor

Re: help with ksh fuser kill script

You are absolutily right. How simple!
Bill Hassell
Honored Contributor

Re: help with ksh fuser kill script

I would strongly endorse Kent's suggestion not to blindly kill processes, especially in a database system. A database needs to be properly shutdown to avoid corrupted pointers or indexes so if the current method fails to provide a clean termination, I would devote full attention to solving the 'busy filesystem' problem first and use fuser to verify things went well.


Bill Hassell, sysadmin
Stuart Abramson_2
Honored Contributor

Re: help with ksh fuser kill script

This is the BCV server. When we take it down, we actually make it disappear and rebuild the entire thing from the primary server with a BCV synch/split.
#
So, we don't care what happens to it. We only shut down Oracle to make it easy to unmount the disks. I could just kill -9 everything. I just don't want to hang anything and force a reboot.
Todd McDaniel_1
Honored Contributor

Re: help with ksh fuser kill script

Stuart Kill -9 still can hang a process or a child process...

I would suggest -15 or -18 first then -9...

-9 will disregard any children and abandon them...when it kills the named process.
Unix, the other white meat.
Jordan Bean
Honored Contributor

Re: help with ksh fuser kill script


I prefer avoiding temp files by using arrays, but they are limited in length.

set -A dirs /dir1 /dir2 /dir3
set -A pids $(fuser -c ${dirs[@]})

# tell me about all the processes
ps -fp "${pids[@]}"

# better yet, use lsof!
lsof -nPp "$(echo ${pids[@]} | sed -e 's/ /,/g')

# terminate them as gracefully as possible
kill -TERM ${pids[@]}

If you want to iterate a long list of processes, then this may help.

fuser -c ${dirs[@]} | while read pids
do
for pid in $pids
do
ps -fp $pid
kill -TERM $pid
done
done

I do hope some of this helps.