Find the answer to your Linux question:
Results 1 to 2 of 2
Hi all. How can i obtain the pid of a process, by using a function? Like, i know if i write x = system("pidof teste"), x is not the pid ...
  1. #1
    Just Joined!
    Join Date
    Oct 2009
    Posts
    11

    Know the output of a command in console

    Hi all.

    How can i obtain the pid of a process, by using a function?

    Like, i know if i write x = system("pidof teste"), x is not the pid of the program teste but it is equal to 0.

    How can i know the output of a command like that, but make it in a a program in C?

    Thanks

  2. #2
    Trusted Penguin elija's Avatar
    Join Date
    Jul 2004
    Location
    Either at home or at work or down the pub
    Posts
    2,303
    In C, the system() command only returns the status (success or error code). You could look at the popen command or simply redirect the stdout for your command to a file and then read that file in your program.

    HTH
    If we hit that bullseye, the rest of the dominoes will fall like a house of cards. Checkmate! (Zapp Brannigan)


    My new blog. It's probably not as good as I think it is.

Posting Permissions

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