What’s the difference between Process.fork and Process.spawn in Ruby 1.9.2

What’s the difference between Process.fork and the new Process.spawn methods in Ruby 1.9.2 Process.fork allows you to run ruby code in another process. Process.spawn allows you to run another program in another process. Basically Process.spawn is like using Process.fork and then calling exec in the forked process, except that it gives you more options. and … Read more

How can I tell if my process is running as Administrator?

Technically, if you want to see if the member is the local administrator account, then you can get the security identifier (SID) of the current user through the User property on the WindowsIdentity class, like so (the static GetCurrent method gets the current Windows user): WindowsIdentity windowsIdentity = WindowsIdentity.GetCurrent(); string sid = windowsIdentity.User.ToString(); The User … Read more

Finding open file descriptors for a process linux ( C code )?

Here’s some code I used to use, I didn’t know about /proc/self (thx Donal!), but this way is probably more generic anyway. I’ve included the required includes for all the functions at the top. #include <string.h> #include <stdio.h> #include <dirent.h> #include <fcntl.h> #include <unistd.h> #include <errno.h> #include <sys/resource.h> #ifndef FALSE #define FALSE (0) #endif #ifndef … Read more

How can I get the PID of the parent process of my application

WMI is the easier way to do this in C#. The Win32_Process class has the ParentProcessId property. Here’s an example: using System; using System.Management; // <=== Add Reference required!! using System.Diagnostics; class Program { public static void Main() { var myId = Process.GetCurrentProcess().Id; var query = string.Format(“SELECT ParentProcessId FROM Win32_Process WHERE ProcessId = {0}”, myId); … Read more

Process.waitFor(), threads, and InputStreams

If your external process expects something on its stdin, you MUST close the getOutputStream. Otherwise you will waitFor forever. Here is the When Runtime.exec() won’t article from JavaWorld which describes different pitfalls of exec method and how to avoid them. From my experience it’s better to consume STDOUT and STDERR of child process ( until … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)