Life of PID in windows - vb.net

Can any one please tell me about the life of a Process Identification (PID) in Windows Server.
Does it remain same for a long process, I mean after a day or two?
I am saving PIDs in my application and want to evaluate the process on the basis of their IDs.

It doesn't change as long as the process is still running.
http://blogs.msdn.com/b/oldnewthing/archive/2011/01/07/10112755.aspx
If you shut down the program, or kill it, and then restart it, you will get a new process id.
If you start the program you can use Process.WaitForExit. If you are starting the programs, I'd start each process in a new thread and use Process.WaitForExit.
msdn.microsoft.com/en-us/library/fb4aw7b8.aspx
For a different process check out the following website: http://alperguc.blogspot.ca/2008/11/c-process-processgetprocessesbyname.html
It shows how to find a process and attach to it's Exited event.

Related

How to kill an unkillable task?

I am using Scilab to access a software called LTSpice (XVIIx64.exe) and whenever I use wmic/taskkill/powershell.exe "Get-Process XVIIx64 | Stop-Process". or whatever killing commands, it doesn't actually kill the process (it does close the program, but it still is there in the memory as shown in the picture below). Once I repeat the code in scilab another instance of LTSPICe (XVIIx64.exe) is created in memory and with time there are so many of them that scilab shuts down as it cannot allocate more memory :(. How can I actually kill this process? It's also strange that in the error message it is mentioned PID XXXX "child process of PID 18208" could not be terminated, however PID 18208 does not show up in tasklist and only PID XXXX shows up (View the attachment).
Did you already checked if it is any malware or something? Do that.
If you've done it and got nothing, then get a backup and format your pc. I think that's the best option.

Is there a way in vb.net to make process start closing my program?

My program checks if there is a new version of itself. If yes it would exit and start an updater that replaces it and then restarts.
My problem is that I haven't found any info on how to make process start right after closing the actual program.
Any suggestions?
Thanks in advance
I intended to add a comment, but I'm too low in points here. The updater itself should probably contain a check to determine whether your application is running an instance, and it should contain a timeout loop that performs this check and factor the timeout following it's startup state. That way you can awaken it, and close your application. The updater should just determine your application is not running, compare versions perform the intended update operation.
a possible solution would also be to create a task via tash sceduler or cron job, starting an out of process application, like CMD.exe.. which brings me to my original comment-question: in regards to what Operating System(s) and Platform(s) is your program intended for?

Getting Notified when a process (daemons & applications included) are created in MAC

I am trying to detect / get notified whenever a new process is created in MAC. The easiest way is to poll all the processes and see if a new process has been launched but that is too time consuming and i wanted to know if i could somehow get some notification whenever a new process is launched using "forked" and "execve". Here is what i have already found :
On how a new process is launched in MAC :
OS X is a variety of Unix. New processes are created with the fork() system call. This creates an almost identical copy of the process that makes the call (the difference is that fork returns 0 in the child and the pid of the child in the parent). It's then normal to use one of the exec() syscalls in the child to transform the child into a process running a different executable.
How is new application launched on Mac?
On getting the list of all processes through polling
http://www.cocoabuilder.com/archive/cocoa/92971-bsd-processes-with-code.html
I have also gone through kAuth kext thing, but it seems beyond my level unless i have some example code for made simple so that i can understand on how to generate the kext and use it in a sample app.
https://developer.apple.com/library/mac/technotes/tn2127/_index.html
NSWorkspace has a notifier but that is only true for applications and not for all processes.
Any tutorial/ sample code with some basic understanding on how to go about this problem, will be greatly appreciated.

Kill process after launching with AuthorizationExecuteWithPrivileges

If I launched a shell script using AuthorizationExecuteWithPrivileges what would be the easiest way to kill the script and any other processes that it spawned.
Thanks
It's running as root, so you can't kill it from a regular-user process. You're going to have to ask it nicely to exit on its own.
Apple has sample code that uses stdout to pass the PID back to the caller.
Use the communications pipe that AuthorizationExecuteWithPrivileges() returns by reference in its last argument, FILE **communicationPipe, to send a message to the child process that asks it to take itself and its descendants out. It can then kill itself and all its descendants using kill(0, SIGINT), or, if more drastic measures are required, SIGKILL.
The message you use can be as simple as closing the file while the child waits for the file to close; at that point, it knows you're done talking to it and it's time to take itself out.
There are some caveats about the descendants that will actually receive this message, for which see the kill(2) manpage. The caveats mostly won't matter so long as the process you started via AEWP hasn't dropped privileges, though one implicit issue is that this approach won't work if any child processes have put themselves in a new process group.

Getting the type (x64 or x86) of a running process in vb.net macro code

I'm writing a macro to automate the process of attaching to the IIS worker process (w3wp.exe, Windows Server 2k8) from Visual Studio. The trouble is that I often two app pools running at any given time, one in x64 mode and one in x86 mode. This means there are two processes called w3wp.exe running at any given time, and the only way to distinguish between them is the mode they are running in. When I use the "Attach to Process" dialog, there is a "Type" column that shows that information so I know which w3wp.exe to attach to, but I can't figure out how to get that information in my macro.
Based on information here, I was able to come up with the following:
Function AttachToProcess(ByVal processName As String) As Boolean
Dim proc As EnvDTE.Process
Dim attached As Boolean
For Each proc In DTE.Debugger.LocalProcesses
If proc.Name = "w3wp.exe" Then
proc.Attach()
attached = True
End If
Next
Return attached
End Function
But half the time this just grabs the wrong process. I need a second if statement to check the mode/type of the process. I've spelunked through the classes using quickwatch as best I can, but just cannot figure out where the information is. Can anyone help? Thanks!
There's not enough info in the Process class to let you find out. You can only get the ProcessID for the process. From there, you'd have to P/Invoke OpenProcess() to get the process handle, then IsWow64Process() to find out if it is a 32-bit process. CloseHandle() to close the process handle. Not actually sure if P/Invoke is possible in a macro. Visit pinvoke.net to get the declarations you'll need.