Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Check if process is running C

  • 22-12-2010 11:27am
    #1
    Registered Users, Registered Users 2 Posts: 2,353 ✭✭✭


    Hi Guys,

    From a C program how could I check if a specified process is running....to break it down, get pid from process name and check if pid is valid.....


    thanks


Comments

  • Registered Users, Registered Users 2 Posts: 24 xonet


    Have a look at the source code for the pgrep utility, i.e. pgrep.c, and it will show you how to do it. Go to http://www.koders.com and search for pgrep.c.


  • Registered Users, Registered Users 2 Posts: 218 ✭✭Tillotson


    I don't know the proper way, this should work though.
    #include <stdlib.h>
    #include <stdio.h>
    
    int main(int argc, char *argv[]) {
            FILE *fd = popen("pgrep rpn", "r");
            char pid[10];
            while (fgets(pid, 10, fd)) {
                    printf("PID: %s", pid);
            }
            return 0;
    }
    


Advertisement