RegisterRegister    Log inLog in    SearchSearch   

Post new topic   Reply to topic
Goto page Previous  1, 2 
View previous topic :: View next topic  
Author Message
LukLuk



PostPosted: Fri Sep 10, 2010 11:26 pm    Post subject: Reply with quote

Hey Smile

When gamecreate starts a process, it looks like

Code:
14748  \_ ./cod4_lnxded-bin 28970 +set dedicated 2 +set net_port 28970 +map mp_backlot +set fs_game mods/promodlive204_lukservers +exec public.cfg +set sv_punkbuster 1


Is it possible to put in "cod4_lnxded-bin 28970" for pidof, so it returns only the PID of the respective Port? I've got Bot-Servers and normal competition Servers and want them to have different priorities.
Back to top
View user's profile Send private message
adbot



PostPosted: Thu Mar 31, 2011 3:57 am 

Kybber



PostPosted: Fri Sep 10, 2010 11:47 pm    Post subject: Reply with quote

No, that is not possible. You'll have to muck about a bit more if you want to
treat certain servers differently.

One way to fetch the pid of a server for which you know the game port is to
use netstat. Try something like
Code:
#!/bin/bash
PORT=28970
pid=`netstat -nlup | grep ":${PORT}" | tr -s " "|cut -d" " -f7|cut -d"/" -f1`
renice -5 ${pid}

This will renice only the process which listens on port 28970 (regardless of
what kind of server it is). Simply repeat with different values for PORT to
handle more servers.

Note: This is just a quick-and-dirty solution I threw together. There are way
smarter ways of doing it, but this should work for your purpose.
Back to top
View user's profile Send private message
LukLuk



PostPosted: Sat Sep 11, 2010 12:06 am    Post subject: Reply with quote

Thanks for this man.

It looks like it does not work 100%.

I've put it into "prchange2" and executed it.

Result:
Code:
78:~# ./prchange2
usage: renice priority [ [ -p ] pids ] [ [ -g ] pgrps ] [ [ -u ] users ]


It looks like as if it does not return the actual PID.
Back to top
View user's profile Send private message
Kybber



PostPosted: Sat Sep 11, 2010 12:14 am    Post subject: Reply with quote

LukLuk wrote:
Thanks for this man.

It looks like it does not work 100%.

I've put it into "prchange2" and executed it.

Result:
Code:
78:~# ./prchange2
usage: renice priority [ [ -p ] pids ] [ [ -g ] pgrps ] [ [ -u ] users ]


It looks like as if it does not return the actual PID.

What is the output of the following (assuming your server actually runds on UDP port 28970)?
Code:
netstat -nlup| grep 28970


I'm leaving on a hunting-trip soon and will be away for a couple of days, but you should be able to fix the issue yourself by adding each piped command in turn on the netstat-line in the script and making sure that it keeps zeroing in on the actual pid, which should be at the far right alongside the process name. If one of the steps doesn't do what you expect it to do, simply modify it slightly and rerun. 'man tr' and 'man cut' should help you out. If I don't check in before I leave: Good luck!
Back to top
View user's profile Send private message
LukLuk



PostPosted: Sat Sep 11, 2010 12:16 am    Post subject: Reply with quote

This is the output:

Code:
78:~# netstat -nlup| grep 28970                                                                                                                                                                             
udp        0      0 78.46.**.***:28970      0.0.0.0:*                           14748/cod4_lnxded-b


Anonymous IP Wink

EDIT: Well, I don't really understand your script. I don't know where he is killing the spaces etc. Sorry for being so unable Sad
Back to top
View user's profile Send private message
Kybber



PostPosted: Sat Sep 11, 2010 3:15 am    Post subject: Reply with quote

It is really quite simple: We're trying to get the number 14748, which is the pid.

First we run netstat -nlup. That command outputs all listening UDP-sockets on the form you posted. We pipe that output into grep, which searches for a line which includes ":28970", since that's the port we're looking for. That leaves us with this:
Code:
udp        0      0 78.46.**.***:28970      0.0.0.0:*                           14748/cod4_lnxded-b

We wish to cut out the last section of this line, so let's try to split it on space (" "). Before we can do that, since there's differing number of spaces between the segments of text, let's reduce all sequential spaces to a single one by piping through the 'tr -s " "' command. That leaves us with this:
Code:
udp 0 0 78.46.**.***:28970 0.0.0.0:* 14748/cod4_lnxded-b

Now let's count. 14748 is on the 6th segment of text. So we cut the line in pieces with " " being the separator, and pick out the sixth segment: 'cut -d" " -f6'. We now have this:
Code:
14748/cod4_lnxded-b

Ok, let's do the same again, but this time we'll need to cut with "/" as the separator, and we want the first segment: 'cut -d"/" -f1. We now have the pid:
Code:
14748

We captured the output of the command by enclosing it in `, and stored the result to the variable pid. we can then pass it to renice: 'renice -5 ${pid}'

The whole difference here compared to my original script, which worked on my PC, is that we need to pick out the sixth segment from the first cut. So try this:

Code:
#!/bin/bash
PORT=28970
pid=`netstat -nlup | grep ":${PORT}" | tr -s " "|cut -d" " -f6|cut -d"/" -f1`
renice -5 ${pid}
Back to top
View user's profile Send private message
LukLuk



PostPosted: Sat Sep 11, 2010 5:35 am    Post subject: Reply with quote

Ah, now it gets clear Smile I was confused by all those signs on such a small space.

I've tested it now with one Port and it WORKS!

Thank you very very much for your help. I hope you enjoy your hunting-trip.
Back to top
View user's profile Send private message
Kybber



PostPosted: Sat Sep 11, 2010 5:43 am    Post subject: Reply with quote

Cool, I'm glad it works Smile

Thanks, but my son got sick, so at best I'll be able to leave tomorrow morning Sad
Back to top
View user's profile Send private message
xiaqinghua1989



PostPosted: Thu Sep 16, 2010 5:41 pm    Post subject: Reply with quote

Grandmother lived in the vegetable garden outside the village. Archlord gold We are just riding a motorcycle off the road, black from the vegetable plots ran the fastest to meet us. Because we go to when they are already fast at noon, so let's eat. I finished the meal, we went out looking for black to play.
When I saw the black when it's like I feel it seems hungry.world of warcraft gold I went to took a steamed bun, and then breaking off a small piece of the next, it said: "The black, if we should want to eat then." Finish, I put bread and threw the air. Black look, at once erected the whole body up. Should first
pandora bracelet
Back to top
View user's profile Send private message
LukLuk



PostPosted: Fri Sep 17, 2010 7:03 am    Post subject: Reply with quote

Damn ad-bots -.- DO NOT CLICK THE LINK!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic All times are GMT + 10 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum powered by phpBB © 2001, 2005 phpBB Group
GameCreate Service Terms | Privacy Policy | © Copyright Mammoth Media 2001-2007
GameCreate™ is a trademark of Mammoth Media Pty Ltd. GameCreate® is a registered trademark in Australia.