3

I'm trying to create a cron job to prevent children at a school from running the Minecraft server. (We actually need them to run the Minecraft client because we use it to teach programming.) The name of the PROCESS is always "java". That's not useful for me.

I found a way using jps and lsof of getting the filesize of all running .jar files. I could kill processes based on that, but it seems messy.

The name of the Application (not the process) that runs the Minecraft server (as show by the Apple logo on the top left corner of the screen) AND its Java class name are both net.minecraft.server.MinecraftServer but I can't ever get that string from the command line, no matter how many variations of ps I try. ps and top always call the process "java". It's easy to find the file name being used, but that's useless because it's easily modified.

Is there a good, clean way to find if the Application or Java class net.minecraft.server.MinecraftServer is running and what its process is?

2

Minecraft Server should be detectable through the arguments passed to its java process.

Over at Unix & Linux, the question kill process based on arguments tackles this problem: how to kill a specific java process based on its command line arguments.

The top answer recommends using pkill with the -f flag to kill based on the arguments associated with a specific process. The final command may be as simple as:

pkill -f 'MinecraftServer'

With regard to using cron, this is fine but Apple recommend migrating to launchd as cron is less efficient.

  • 1
    Good tip regarding pkill. But doesn't this rely on the students not renaming minecraft_server.jar to something a bit less obvious? – nohillside Mar 14 '14 at 9:09
  • 1
    In which case, it may be worth considering boosting the script to pkill any java process launched with a path outside of a specific, administrator controlled, directory. Effectively whitelisting certain java processes. – Graham Miln Mar 14 '14 at 9:34
  • That makes sense, but I'm not comfortable whitelisting some Java processes. What if another legitimate Java Application is used in the future? I think that killing the process by filesize is safer than that. Looking into the arguments is not useful because the students will quickly figure out they can rename the JAR file. – eje211 Mar 14 '14 at 14:54
  • And, @GrahamMiln, the process is called "java", not "MinecraftServer". If the process were called "MinecraftServer", I'd have had the whole thing done in a minute. – eje211 Mar 14 '14 at 18:00
  • 1
    The -f matches the arguments to the java process, thus matching MinecraftServer if it is in the launch command. Without -f, the command would only search against the process name. – Graham Miln Mar 14 '14 at 18:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .