コード例 #1
0
ファイル: Wait.cs プロジェクト: Glimmers/PosixSharp
 static void Wait(int pid)
 {
     try
     {
         Process.GetProcessById(pid).WaitForExit();
     }
     catch (ArgumentException e)
     {
         Stdio.perror("Can't wait on process: " + e.Message);
     }
 }
コード例 #2
0
ファイル: Wait.cs プロジェクト: Glimmers/PosixSharp
        static void Wait(int[] pids)
        {
            Dictionary <int, Process> toWaitFor = new Dictionary <int, Process>();

            // sort through the list, getting actual processes, sending to error
            // processes that don't exist, etc.

            foreach (int pid in pids)
            {
                try
                {
                    Process p = Process.GetProcessById(pid);
                    p.EnableRaisingEvents = true;
                    toWaitFor.Add(pid, p);

                    // When the process' exit event triggers, remove it from the list of procs we're waiting on
                    p.Exited += (object o, EventArgs e) =>
                    {
                        if (toWaitFor.ContainsKey(pid))
                        {
                            toWaitFor.Remove(pid);
                        }
                    };

                    // Handle potential race condition for when the process finishes after we add it to the
                    // dict, but before we add the handler.
                    if (p.HasExited)
                    {
                        if (toWaitFor.ContainsKey(pid))
                        {
                            toWaitFor.Remove(pid);
                        }
                    }
                }
                catch (ArgumentException e)
                {
                    Stdio.perror("Can't wait on process " + pid + ": " + e.Message);

                    // Something had gone wrong, make sure we aren't going to be locking
                    // on a dead process
                    if (toWaitFor.ContainsKey(pid))
                    {
                        toWaitFor.Remove(pid);
                    }
                }
            }

            // Spinwait until all processes finish and remove themselves from the list

            System.Threading.SpinWait.SpinUntil(() => { return(toWaitFor.Count == 0); });
        }
コード例 #3
0
ファイル: FileSystem.cs プロジェクト: Glimmers/PosixSharp
        static int Unlink(string filename)
        {
            int retVal = 0;

            try
            {
                File.Delete(filename);
            }
            catch (Exception e)
            {
                Stdio.perror("Unable to delete file: " + e.Message);
                retVal = -1;
            }
            return(retVal);
        }
コード例 #4
0
ファイル: FileSystem.cs プロジェクト: Glimmers/PosixSharp
        static int MkDir(string toMake)
        {
            int retVal = 0;

            try
            {
                Directory.CreateDirectory(toMake);
            }
            catch (Exception e)
            {
                Stdio.perror("Unable to create directory: " + e.Message);
                retVal = -1;
            }
            return(retVal);
        }
コード例 #5
0
ファイル: SimpleUtils.cs プロジェクト: Glimmers/PosixSharp
        public static int Cd(string directory)
        {
            int retval = 0;

            try
            {
                Environment.CurrentDirectory = directory;
            }
            catch (Exception e)
            {
                Stdio.perror("Invalid directory:" + e.Message);
                retval = 1;
            }

            return(retval);
        }
コード例 #6
0
ファイル: FileSystem.cs プロジェクト: Glimmers/PosixSharp
        static int RmDir(string toDelete, bool recursive = false)
        {
            int retVal = 0;

            try
            {
                Directory.Delete(toDelete, recursive);
            }
            catch (Exception e)
            {
                Stdio.perror("Unable to delete directory: " + e.Message);
                retVal = -1;
            }

            return(retVal);
        }