0

Given the name of a service or daemon, is there some way by which I can get the location of that service from a C++ program in Linux? I hope, one way is to search the proc filesystem using it pid. Does there exist some Linux functions for this?

Thank You

edit: To be more specific I am working on Linux equivalent code for this program in Windows.

Community
  • 1
  • 1
Jackzz
  • 1,417
  • 4
  • 24
  • 53

1 Answers1

0

You can execute the system function and redirect its output to a file. Later on read that file. For example,

system ("which rsyslogd >service.out");

Then in the program, you can read service.out.

kjohri
  • 1,166
  • 11
  • 10
  • What if my service is not in a standard location as bin or sbin, etc – Jackzz Feb 05 '15 at 10:59
  • It should be in one of the directories in the PATH. Any particular reason for keeping it outside the directories in PATH? – kjohri Feb 05 '15 at 11:10
  • May be in some cases will have to do so. – Jackzz Feb 05 '15 at 11:17
  • Well, in that case, instead of "which" you can use the "find" command in the system function and then use the output of "find" in the program. – kjohri Feb 05 '15 at 11:33