Exemplo n.º 1
0
        private UnixProcessInfo parseProcessInfo(string line, DateTime baseTime)
        {
            UnixProcessInfo retInfo = new UnixProcessInfo();
            char[] elemseps = { ' ', '\t' };
            string[] ffields = line.Split(elemseps, 9, StringSplitOptions.RemoveEmptyEntries);
            if (ffields.GetUpperBound(0) < 8)
                return null;
            uint pid, ppid;
            int prio;
            if (!uint.TryParse(ffields[0], out pid))
                return null;
            if (!uint.TryParse(ffields[2], out ppid))
                return null;
            if (!int.TryParse(ffields[3], out prio))
                return null;

            retInfo.Pid = pid;
            retInfo.PPid = ppid;
            retInfo.Command = ffields[8];
            retInfo.Prio = prio;
            if (ffields[4] != ffields[0])
                retInfo.Class = ffields[4];
            else                                    // No support for "class", so we...
                retInfo.Class = "Unclassified";     // called ps with the pid keyword repeated
            retInfo.Tty = ffields[7];
            retInfo.User = ffields[1];
            retInfo.CpuTime = psTime2Secs(ffields[5]);
            retInfo.StartTime = baseTime.AddSeconds(-psTime2Secs(ffields[6]));

            return retInfo;
        }
Exemplo n.º 2
0
        public ProcessItemTypeGeneratorTests()
        {
            this.OvalDefinitionsSample = ProbeHelper.GetFakeOvalDefinitions("definitions_all_unix.xml");

            var processInfo1 = new UnixProcessInfo() { Command = "http", Pid = 20, PPid = 0, Tty = "tty", User = "******" };
            var processInfo2 = new UnixProcessInfo() { Command = "ftp", Pid = 21, PPid = 20, Tty = "tty", User = "******" };
            var processInfo3 = new UnixProcessInfo() { Command = "ssh", Pid = 22, PPid = 0, Tty = "tty", User = "******" };
            var processInfo4 = new UnixProcessInfo() { Command = "named", Pid = 23, PPid = 0, Tty = "tty", User = "******" };

            this.FakeProcessInfoList = new UnixProcessInfo[] { processInfo1, processInfo2, processInfo3, processInfo4 }.ToList();
        }
Exemplo n.º 3
0
 private OVAL.SystemCharacteristics.Unix.process_item CreateProcessItem(UnixProcessInfo targetProcess)
 {
     return new OVAL.SystemCharacteristics.Unix.process_item()
     {
         command = OvalHelper.CreateItemEntityWithStringValue(targetProcess.Command),
         pid = OvalHelper.CreateItemEntityWithIntegerValue(targetProcess.Pid.ToString()),
         ppid = OvalHelper.CreateItemEntityWithIntegerValue(targetProcess.PPid.ToString()),
         priority = OvalHelper.CreateItemEntityWithIntegerValue(targetProcess.Prio.ToString()),
         tty = OvalHelper.CreateItemEntityWithStringValue(targetProcess.Tty),
         user_id = OvalHelper.CreateItemEntityWithIntegerValue(targetProcess.User),
         start_time = new OVAL.SystemCharacteristics.EntityItemStringType() { status = OVAL.SystemCharacteristics.StatusEnumeration.notcollected },
         exec_time = new OVAL.SystemCharacteristics.EntityItemStringType() { status = OVAL.SystemCharacteristics.StatusEnumeration.notcollected },
         ruid = new OVAL.SystemCharacteristics.EntityItemIntType() { status = OVAL.SystemCharacteristics.StatusEnumeration.notcollected },
         scheduling_class = new OVAL.SystemCharacteristics.EntityItemStringType() { status = OVAL.SystemCharacteristics.StatusEnumeration.notcollected }
     };
 }
Exemplo n.º 4
0
        private UnixProcessInfo parseProcessInfo(string line, DateTime baseTime)
        {
            UnixProcessInfo retInfo = new UnixProcessInfo();

            char[]   elemseps = { ' ', '\t' };
            string[] ffields  = line.Split(elemseps, 9, StringSplitOptions.RemoveEmptyEntries);
            if (ffields.GetUpperBound(0) < 8)
            {
                return(null);
            }
            uint pid, ppid;
            int  prio;

            if (!uint.TryParse(ffields[0], out pid))
            {
                return(null);
            }
            if (!uint.TryParse(ffields[2], out ppid))
            {
                return(null);
            }
            if (!int.TryParse(ffields[3], out prio))
            {
                return(null);
            }

            retInfo.Pid     = pid;
            retInfo.PPid    = ppid;
            retInfo.Command = ffields[8];
            retInfo.Prio    = prio;
            if (ffields[4] != ffields[0])
            {
                retInfo.Class = ffields[4];
            }
            else                                    // No support for "class", so we...
            {
                retInfo.Class = "Unclassified";     // called ps with the pid keyword repeated
            }
            retInfo.Tty       = ffields[7];
            retInfo.User      = ffields[1];
            retInfo.CpuTime   = psTime2Secs(ffields[5]);
            retInfo.StartTime = baseTime.AddSeconds(-psTime2Secs(ffields[6]));

            return(retInfo);
        }