LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-07-2010, 07:50 PM   #1
Marin_
LQ Newbie
 
Registered: Dec 2009
Posts: 4

Rep: Reputation: 0
read the output in console by a function in c


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
 
Old 03-07-2010, 09:26 PM   #2
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Buster (Fluxbox WM)
Posts: 1,389
Blog Entries: 52

Rep: Reputation: 358Reputation: 358Reputation: 358Reputation: 358
If you just want to read the (text) output of a command, you can use popen, ie:
Code:
FILE *f = popen("pidof teste", "r");
char buf[256];
fgets(buf, sizeof(buf), f);
If you wanted to do this purely in C, you would have to do the process list search yourself using the process information, but that is more than just a few lines of code.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
can't read from the device driver using read() function. parthi_s Linux - Newbie 1 03-23-2009 06:16 AM
how to read console output from remote server gogoabc Programming 1 01-21-2009 04:01 AM
Help with the read() function in C smoothdogg00 Programming 4 09-25-2006 08:44 PM
PHP function system() - format the output fatrandy13 Programming 5 09-20-2006 08:53 AM
Bash Select Function: Formatting Output mooreted Linux - General 2 03-28-2004 06:26 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration