Talk:Scripts:RestartScript

From BF2 Technical Information Wiki
Revision as of 04:05, 31 July 2005 by Dst (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
 #setting the column boundries for cutting the pid from ps
 char1=1
 char2=6
 pid=$(ps ax |grep $procName |cut -c$char1-$char2)

Ever interested in cutting lines of code, ps is pretty powerful stuff. You don't need to set column boundaries or anything as long as you tell ps just to list the named process that you're looking for, and then only the parent id of the threads, so no matter which thread of the bf2 process ps gives you, it's the parent id (the one that needs to die if the server gets out of hand).

You should be able to get rid of the first code block and replace the second with this:

 pid=$(ps -C bf2 -o pgid|egrep -m 1 [0-9]+)

In ps, the -C the filters by command name, 'bf2'; -o is the output format, with pgid being the parent group id of the processes named bf2, each one will return the pid of your bf2 process. There are normally five of these, so pipe it through egrep matching any number occuring one or more times, and limit the matches to 1.

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox