Find the answer to your Linux question:
Results 1 to 4 of 4
Hello Guys, I have a problem,I coded a gtk program(Using C) which i want it to run only in one process.i.e let say i started the program ./helloworld and leave ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2006
    Location
    Bangalore , India
    Posts
    29

    Thumbs up One instance of a program


    Hello Guys,
    I have a problem,I coded a gtk program(Using C) which i want it to run only in one process.i.e let say i started the program ./helloworld and leave it running. and i run ./helloworld in another terminal it has to say the program is already running .So anybody haev a clue how to do this.... If you do please help me out i need it very urgently.

    thank YOU

  2. #2
    Linux Engineer Javasnob's Avatar
    Join Date
    Jul 2005
    Location
    Wisconsin
    Posts
    942
    You can create a temporary file and delete it on exit, or you can check the process list. I'm positive that there's more and better ways to do it, though. Just a few ideas.
    Flies of a particular kind, i.e. time-flies, are fond of an arrow.

    Registered Linux User #408794

  3. #3
    Linux User Krendoshazin's Avatar
    Join Date
    Feb 2005
    Location
    London, England
    Posts
    471
    Quote Originally Posted by Javasnob
    You can create a temporary file and delete it on exit, or you can check the process list. I'm positive that there's more and better ways to do it, though. Just a few ideas.
    The way gpm, dhcpcd, syslog, and probably a few others, do this is by creating a file in /var/run called program.pid, such as gpm.pid, within this file contains the pid of the program being run, but on it's own the existence of the file indicates that one existence of the program is already being run, and that gets removed when the program ends.

  4. #4
    Just Joined!
    Join Date
    Jun 2006
    Location
    Bangalore , India
    Posts
    29

    Another small doubt

    HI

    Thanks a lot for you response guys it was very helpful,But i have a small doubt.Is it possible for a user to delete the file i created in /var/run/ while the program is running ,because if it is possible what's the use he will delete that file and runs another instance of that program........... what should i do?

Posting Permissions

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