A program that Linux determines whether the process is already running

Source: Internet
Author: User

1   BOOL2 serverprocess::isalreadyrunning ()3   {4 #ifndef __linux__5Warninglog (<<"can ' t check if process already running on the platform (not implemented yet)");6      return false;7   #else8      if(mpidfile.size () = =0)9      {Ten         //if no PID file specified, we don't make an any check One         return false; A      } -    - pid_t running_pid; theStd::ifstream _pid (Mpidfile.c_str (), Std::ios_base::inch); -      if(!_pid.good ()) -      { -         //if the file doesn ' t exist or can ' t be opened, just ignore +         return false; -      } +_pid >>Running_pid; A _pid.close (); at    -Stacklog (<< mpidfile <<"contains PID"<<running_pid); -    -Data Ourproc = data ("/proc/self/exe"); -Data Otherproc = data ("/proc/") + data (running_pid) + data ("/exe"); -      Charour_exe[513], other_exe[513]; in      intbuf_size; -    toBuf_size = Readlink (Ourproc.c_str (), Our_exe, +); +      if(Buf_size <0|| Buf_size = = +) -      { the         //If Readlink fails, just ignore *         return false; $      }Panax NotoginsengOur_exe[buf_size] =0; -    theBuf_size = Readlink (Otherproc.c_str (), Other_exe, +); +      if(Buf_size <0|| Buf_size = = +) A      { the         //If Readlink fails, just ignore +         return false; -      } $Other_exe[buf_size] =0; $    -      if(strcmp (Our_exe, other_exe) = =0) -      { theErrLog (<<"already running PID:"<<running_pid); -         return true;Wuyi      } the      return false; -   #endif Wu}

A program that Linux determines whether the process is already running

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.