#pragma warning restore IDE1006 protected override async Task ExecuteAsync(CancellationToken stoppingToken) { _logger.LogInformation($"Current OS: {Environment.OSVersion.Platform}"); var pid = Syscall.getpid(); Console.WriteLine($"Current PID: {pid}"); var procDirectory = $"/proc/{pid}"; var openFdPaths = Directory.EnumerateFiles($"{procDirectory}/fd"); var openRegularFiles = openFdPaths.Select(p => new { symlinkPath = p, linkTargetPath = Mono.Unix.UnixPath.ReadLink(p), fd = int.Parse(p.Substring(procDirectory.Length + 4)), }) .Where(f => IsRegularFile(f.fd)); Console.WriteLine("Files that this process has open:"); foreach (var f in openRegularFiles) { Console.WriteLine(f.linkTargetPath); } // using (StreamReader sr = new StreamReader($"{procDirectory}/status")) // { // string file = await sr.ReadToEndAsync(); // _logger.LogInformation(file); // } var tv = new TimeVal(); gettimeofday(tv, null); var timeOffset = DateTimeOffset.FromUnixTimeSeconds(tv.tv_sec); _logger.LogInformation($"Seconds elapsed since Unix epoch: {timeOffset.DateTime}"); while (!stoppingToken.IsCancellationRequested) { _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now); await Task.Delay( 1000, stoppingToken); } }
private static extern int gettimeofday(TimeVal timeVal, TimeZone timeZone);