Windows get number of spawns of a single process?
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Windows get number of spawns of a single process?
Is there a function to get a pid from a filename? I'm used to doing C under Windows and not POSIX-compliant systems.
OK, not looking for that anymore. I need something to get the number of spawns of the same process. On Windows.
(I'm writing a fork bomb killer for fun. )
Thanks,
Troy
OK, not looking for that anymore. I need something to get the number of spawns of the same process. On Windows.
(I'm writing a fork bomb killer for fun. )
Thanks,
Troy
Last edited by Troy Martin on Sat Nov 15, 2008 8:19 pm, edited 1 time in total.
-
- Member
- Posts: 2566
- Joined: Sun Jan 14, 2007 9:15 pm
- Libera.chat IRC: miselin
- Location: Sydney, Australia (I come from a land down under!)
- Contact:
Re: C function to get pid from filename?
Why would a filename have a PID?
Unless you're talking about a "<app>.pid" file, which is just a normal text file with the PID stored as the only content.
Unless you're talking about a "<app>.pid" file, which is just a normal text file with the PID stored as the only content.
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: C function to get pid from filename?
Sorry if I wasn't clear, I mean get the PID of a process that I know the filename of.
Or, if better, get the PID of any process that has >10 copies running at one time.
Or, if better, get the PID of any process that has >10 copies running at one time.
-
- Member
- Posts: 2566
- Joined: Sun Jan 14, 2007 9:15 pm
- Libera.chat IRC: miselin
- Location: Sydney, Australia (I come from a land down under!)
- Contact:
Re: C function to get pid from filename?
Oh, right.
I'm not 100% sure how to go about that with a *nix system because I haven't spent much time programming on one (I'm a Windows programmer too, the closest I get to *nix programming is my OS user software packages).
I'm sure there's a command you could run that would show you what's running, and then you'd need to parse that.
I'm not 100% sure how to go about that with a *nix system because I haven't spent much time programming on one (I'm a Windows programmer too, the closest I get to *nix programming is my OS user software packages).
I'm sure there's a command you could run that would show you what's running, and then you'd need to parse that.
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: Windows get number of spawns of a single process?
I think I'm going to stick to Windows and use taskkill and friends to do this.
Thanks though, pcmattman!
Thanks though, pcmattman!
-
- Member
- Posts: 566
- Joined: Tue Jun 20, 2006 9:17 am
Re: Windows get number of spawns of a single process?
In C# following pice of code will do the trick l
The Win32 api based soln may take a bit more time, i do not have any reference handy right now
Regards
Sandeep
Code: Select all
using System.Diagnostics ;
.....
....
public void some_func()
{
Process p = Process.GetProcessbyName("procname");
Console.WriteLine(p.Id.ToString());
}
Regards
Sandeep
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: Windows get number of spawns of a single process?
You keep changing your username, Sandeep, it's hard to tell who you are!
Thanks for the code, I'll see if there's something similar in the Win32 API.
Thanks for the code, I'll see if there's something similar in the Win32 API.
-
- Member
- Posts: 2566
- Joined: Sun Jan 14, 2007 9:15 pm
- Libera.chat IRC: miselin
- Location: Sydney, Australia (I come from a land down under!)
- Contact:
Re: Windows get number of spawns of a single process?
There's no real ability to "fork" in the Windows API (though there is a function that does a similar action).
A fork bomb should just involve constantly calling fork():
That'll fill up the RAM and swap with many copies of the same address space.
A fork bomb should just involve constantly calling fork():
Code: Select all
while(1)
{
fork();
}
Re: Windows get number of spawns of a single process?
Oh, i remembered... i've made a "paint" bomb(you can change it's name ):
bomb.bat:
have fun with it
bomb.bat:
Code: Select all
@echo off
paint
bomb
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: Windows get number of spawns of a single process?
Not sure if I mentioned this, but this fork bomb is meant to kill off other fork bombs. It needs to detect if there are any processes with >15 spawns and kills them all before they can crash the machine.
Re: Windows get number of spawns of a single process?
so, there is bomb, there isn't!
Re: Windows get number of spawns of a single process?
I don't know if any Windows API exists to query how many times a process has called the CreateProcess function, but you could inject a DLL into the target process and have it patch/redirect the CreateProcess function... Dll redirection won't work, since this function is located in kernel32.dll, and that's on the "known DLLs list" (list of DLLs for which LoadLibrary uses only the %windir%\System32 or %windir%\SysWOW64 directory)
-
- Member
- Posts: 204
- Joined: Thu Apr 12, 2007 8:15 am
- Location: Michigan
Re: Windows get number of spawns of a single process?
See this example.
simply count the number of processes that list the executable in question as a module, remember their process IDs, if the count is too large (or, perhaps it'd be better to test if the count increases ridiculously quickly), terminate the list of process IDs associated with the executable.
Is that what you're looking for?
simply count the number of processes that list the executable in question as a module, remember their process IDs, if the count is too large (or, perhaps it'd be better to test if the count increases ridiculously quickly), terminate the list of process IDs associated with the executable.
Is that what you're looking for?
Some people are offended by the verifiable truth; such people tend to remain blissfully unencumbered by fact.
If you are one of these people, my posts may cause considerable discomfort. Read at your own risk.
If you are one of these people, my posts may cause considerable discomfort. Read at your own risk.
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: Windows get number of spawns of a single process?
Yeah, that's what I'm thinking! Thanks!