LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 03-09-2010, 08:17 AM   #1
beckettisdogg
Member
 
Registered: Mar 2009
Distribution: Slackware 13.0
Posts: 60

Rep: Reputation: 16
When I write a C program and use system command


When I write a C program, and use the system command in the middle of the program to take advantage of one of UNIX commands,

does the UNIX command become a part of the binary C program, or is the C program going to call the UNIX command whenever necessary?

the reason I am asking this is, because I might run the C program under different UNIX systems~

Thanks, experts @ Linux Questions~

Last edited by beckettisdogg; 03-09-2010 at 08:20 AM.
 
Old 03-09-2010, 08:25 AM   #2
jamescondron
Member
 
Registered: Jul 2007
Location: Scunthorpe, UK
Distribution: Ubuntu 8.10; Gentoo; Debian Lenny
Posts: 961

Rep: Reputation: 69
No, otherwise using system() on an input, which may change, would need the entire system compiled in

As a caveat, consider finding a library or wrapper for the command you want, security and speed concerns
 
Old 03-09-2010, 08:28 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
It calls the Unix command---just as if it were calling a kernel function defined in the API.

The only way to make the command part of your binary would be to get the source and compile it in.
 
1 members found this post helpful.
Old 03-09-2010, 09:11 AM   #4
beckettisdogg
Member
 
Registered: Mar 2009
Distribution: Slackware 13.0
Posts: 60

Original Poster
Rep: Reputation: 16
excellent answer, old friend pixellany~~ might need some more help from you shortly.

well maybe I can ask right now.

Can we find the source code of just about any UNIX command? and integrate into our C programs? or... source code of programs equivalent to well-known UNIX commands?

pixel you are da (wo)man
 
Old 03-09-2010, 10:27 AM   #5
giammy
Member
 
Registered: Feb 2010
Posts: 36

Rep: Reputation: 20
Quote:
Originally Posted by beckettisdogg View Post
excellent answer, old friend pixellany~~ might need some more help from you shortly.

well maybe I can ask right now.

Can we find the source code of just about any UNIX command? and integrate into our C programs? or... source code of programs equivalent to well-known UNIX commands?

pixel you are da (wo)man
A good place to get many unix command is busybox
(clean and compact code!)

http://busybox.net/

bye
giammy
 
Old 03-09-2010, 10:48 AM   #6
jf.argentino
Member
 
Registered: Apr 2008
Location: Toulon (France)
Distribution: FEDORA CORE
Posts: 492

Rep: Reputation: 50
Quote:
Can we find the source code of just about any UNIX command?
Yes and no, it depends on the command version, for example you can find the source code of the GNU version as they are free, and so it is for the system calls: if you're using *BSD, OpenSolaris or Linux, you can find system calls source codes, but you can't for proprietary UNIX version like AIX, Solaris, HP-UX...

Quote:
and integrate into our C programs? or... source code of programs equivalent to well-known UNIX commands?
C is the UNIX native language... The implication is that you'll find a C library for almost all UNIX standard utilities, whatever they're closed or not. I'm mean, you don't need to access the function source code to call it in your C program, you only need a library to link on and a header file. If it wasn't the case nobody won't be able to program anything on a closed sources OS (excepting the OS owner)... The difficulties are to find the C interface regarding what you want to do, google is your friend here, and write C code portable along different UNIX flavor, if you need to, since sometimes functions interface could slightly differe...
 
  


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
write a C++ program yewjingcho Programming 14 11-01-2007 07:05 PM
how to write command line program? vito_huang Linux - Software 3 04-14-2006 01:20 AM
How can I Write a sniffer program in System Programming touqeeransar Programming 3 03-07-2006 12:51 PM
Viewing program messages when program isn't run from command line? Locura Linux - Software 1 09-27-2003 09:19 AM
C program code calling a Linux system command Linh Programming 1 06-05-2003 02:44 PM


All times are GMT -5. The time now is 11:29 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration