need to see if C program is already running in UNIX

This is a discussion on need to see if C program is already running in UNIX within the C Programming forums, part of the General Programming Boards category; My C program in UNIX can be triggered multiple times, but I want only the first one to run completely, ...

  1. #1
    Unregistered
    Guest

    Unhappy need to see if C program is already running in UNIX

    My C program in UNIX can be triggered multiple times, but I want only the first one to run completely, while others coming out seeing that already an instance is running. Please help me to achieve this.

    I was trying with getenv() and putenv(), but i am not having my variables in UNIX.

    Thanks,

  2. #2
    B26354 Deckard's Avatar
    Join Date
    Jan 2002
    Posts
    633
    A simple way to do this would be to have your application look for a particular file in the /tmp directory. If it exists, exit. If it doesn't, create it and continue on. The application must remove the temporary file before completing.
    Jason Deckard

  3. #3
    Registered User
    Join Date
    Aug 2001
    Location
    computers/ theatre, travelingstudentL>- Northern California NativeNorthern California3D&Tie-DyeStudent1>. Admirer of C Bangalore Net surfingTeacher >/ >0 nagpurteaching >1  >2
    Posts
    61
    I just wrote a function to do this.

    I used popen("ps -A", "r")
    then read each line and used strstr to search for the command name.

    Input for the function is the command name,
    Output is the number of instances of the executable

    I also wrote another function to get the command name based on a pid. So my call looks like:
    if(exeRunning(exeName(getpid())) > 1) exit(0);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Finding Program Running Time
    By pf732k3 in forum C Programming
    Replies: 6
    Last Post: 03-18-2008, 01:56 PM
  2. Stop program from running twice?
    By Abda92 in forum C Programming
    Replies: 19
    Last Post: 03-17-2008, 01:35 PM
  3. Determaining if a program is running
    By WebmasterMattD in forum Linux Programming
    Replies: 4
    Last Post: 04-09-2002, 04:36 PM
  4. Why is my program running away?
    By badkitty in forum C++ Programming
    Replies: 4
    Last Post: 09-19-2001, 04:27 PM
  5. Running program
    By muffin in forum C Programming
    Replies: 5
    Last Post: 08-30-2001, 10:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21