Find the answer to your Linux question:
Results 1 to 5 of 5
Hi, is that possible to get the process id, using a process name in c program. In shell it is possible using pgrep, but in c program ?? Does any ...
  1. #1
    Just Joined!
    Join Date
    Oct 2008
    Posts
    30

    Lightbulb Getting process ID using process name in C ??

    Hi, is that possible to get the process id, using a process name in c program.
    In shell it is possible using pgrep, but in c program ??
    Does any one has the answer ??

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    I'm not aware of a standard function to get this information, but you can look at the source for the pidof system command to see how it does that.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    FWIW, most functions that do this sort of thing access the /proc file system where process ids of all running processes exist as directories and they have entries for such things as the command line it was started with, a link to the executable that is running the process, etc.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  4. #4
    Just Joined!
    Join Date
    Oct 2008
    Posts
    30
    Quote Originally Posted by Rubberman View Post
    FWIW, most functions that do this sort of thing access the /proc file system where process ids of all running processes exist as directories and they have entries for such things as the command line it was started with, a link to the executable that is running the process, etc.
    you can refer this link:
    linuxforums.org/forum/linux-programming-scripting/40078-c-printing-linux-process-table.htm

    few question arises with this link
    if you want to create a single instance application in linux using daemon process, then problem arises.
    1. when you run the daemon say XX 1st time, it checks for the process XX. the process exist since we are running the same, so it will say that the program is running and it will come out. how to solve this problem.

  5. #5
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Quote Originally Posted by jayasekar.k View Post
    you can refer this link:
    linuxforums.org/forum/linux-programming-scripting/40078-c-printing-linux-process-table.htm

    few question arises with this link
    if you want to create a single instance application in linux using daemon process, then problem arises.
    1. when you run the daemon say XX 1st time, it checks for the process XX. the process exist since we are running the same, so it will say that the program is running and it will come out. how to solve this problem.
    Most daemon processes that have to run as a singleton (only one instance), will check for other processes that are using their resources, but they usually check the PID of the processes to make sure that it isn't "self".
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...