MCPcopy Create free account
hub / github.com/ByConity/ByConity / isRunning

Function isRunning

programs/install/Install.cpp:614–682  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

612 }
613
614 UInt64 isRunning(const fs::path & pid_file)
615 {
616 UInt64 pid = 0;
617
618 if (fs::exists(pid_file))
619 {
620 try
621 {
622 ReadBufferFromFile in(pid_file.string());
623 if (tryReadIntText(pid, in))
624 {
625 fmt::print("{} file exists and contains pid = {}.\n", pid_file.string(), pid);
626 }
627 else
628 {
629 fmt::print("{} file exists but damaged, ignoring.\n", pid_file.string());
630 fs::remove(pid_file);
631 }
632 }
633 catch (const Exception & e)
634 {
635 if (e.code() != ErrorCodes::FILE_DOESNT_EXIST)
636 throw;
637
638 /// If file does not exist (TOCTOU) - it's ok.
639 }
640 }
641
642 if (!pid)
643 {
644 auto sh = ShellCommand::execute("pidof clickhouse-server");
645
646 if (tryReadIntText(pid, sh->out))
647 {
648 fmt::print("Found pid = {} in the list of running processes.\n", pid);
649 }
650 else if (!sh->out.eof())
651 {
652 fmt::print("The pidof command returned unusual output.\n");
653 }
654
655 WriteBufferFromFileDescriptor std_err(STDERR_FILENO);
656 copyData(sh->err, std_err);
657
658 sh->tryWait();
659 }
660
661 if (pid)
662 {
663 if (0 == kill(pid, 0))
664 {
665 fmt::print("The process with pid = {} is running.\n", pid);
666 }
667 else if (errno == ESRCH)
668 {
669 fmt::print("The process with pid = {} does not exist.\n", pid);
670 return 0;
671 }

Callers 2

stopFunction · 0.85

Calls 12

tryReadIntTextFunction · 0.85
removeFunction · 0.85
killFunction · 0.85
throwFromErrnoFunction · 0.85
tryWaitMethod · 0.80
existsFunction · 0.50
printFunction · 0.50
executeFunction · 0.50
copyDataFunction · 0.50
stringMethod · 0.45
codeMethod · 0.45
eofMethod · 0.45

Tested by

no test coverage detected