LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-31-2008, 07:23 PM   #1
cyberfox007
LQ Newbie
 
Registered: Jan 2007
Distribution: Yellow Dog Linux v5.0
Posts: 8

Rep: Reputation: 0
Issuing commands from c++ program to the shell


Hello all

I need to write a c++ program where when i run it it issues commands to the shell where i need to get information from /proc files like cpuinfo, version, and meminfo and have it displayed on the screen. how do i configure my c++ program to do this?

also are there any shell commands where it displays information about kernel and the current running process on the system?.

Thank You
 
Old 01-31-2008, 09:09 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
"man popen"
<= Standard C/C++ API for executing a shell command and reading the input

"man uname"
<= Gives kernel info

"man ps"
<= Gives process info

There are many, many, MANY alternatives to each of the above. Just Google around a little bit.
 
Old 01-31-2008, 10:21 PM   #3
ludwig
Member
 
Registered: Jun 2002
Location: Orange County, CA
Distribution: Debian (squeeze), kernel 2.6.30-2-amd64
Posts: 32

Rep: Reputation: 15
I just tried "man popen" and I don't have any man pages regarding that topic installed on my system (I'm running a Debian 2.6.22 kernel). What package(s) do I need for this function? I googled "popen" and it looks pretty interesting...
 
Old 01-31-2008, 11:48 PM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
manpages-dev
 
Old 02-01-2008, 05:35 AM   #5
gr.manju
LQ Newbie
 
Registered: Oct 2007
Posts: 2

Rep: Reputation: 0
hi

man proc
in proc man page check in which file you will get the required information (in proc directory)
just call cat filename command in system or execl
but make sure you have the root permission to cat files in proc directory
format the cat output to your convenience

or you can use commands which are already available
 
Old 02-01-2008, 08:52 AM   #6
akhorus
LQ Newbie
 
Registered: Jan 2008
Location: Cordoba, Argentina
Distribution: Fedora, SuSE, Ubuntu, Mandriva
Posts: 21

Rep: Reputation: 15
Hi cyberfox007, I don't think you need to "configure" your C++ program in any special way.
You just open any file in the /proc directory for reading.
For example, in C, it would be something like:

fd = fopen("/proc/version","r");

Then you must parse the info you need from those files (just treat them as normal files)...
This links might help you:
http://linux.die.net/man/5/proc
http://search.cpan.org/src/VSEGO/Lin...1.00/stat.html

Some commands that will help you see the current running process on the system are 'ps' and 'top'.
 
Old 02-01-2008, 10:17 AM   #7
TransAMrit
LQ Newbie
 
Registered: Jun 2007
Posts: 4

Rep: Reputation: 0
Also, you don't need to run a shell command and parse its output to find out about the running kernel - see "man 2 uname".
 
Old 02-03-2008, 04:06 AM   #8
z940303
LQ Newbie
 
Registered: Jun 2007
Posts: 7

Rep: Reputation: 0
The pstreams library is a general C++ solution (can be used for many applications).
Have not tested it out, will do soon.

http://pstreams.sourceforge.net/

Thanks for the interesting post.
 
  


Reply



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
about shell commands nesta Linux - Newbie 3 12-12-2006 05:40 PM
Alias or shell script to confirm 'exit' commands from a shell rose_bud4201 Programming 2 03-08-2006 02:34 PM
make c-program that accepts shell commands and execute them boeroe Programming 4 02-18-2005 08:41 AM
Issuing Telnet commands via bash scripts Kaj Programming 2 01-02-2005 11:44 PM
shell commands! krishlinux General 1 10-05-2003 04:47 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:25 PM.

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
Open Source Consulting | Domain Registration