LinuxQuestions.org
Review your favorite Linux distribution.
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 02-11-2009, 06:39 AM   #1
puneetnepsam
LQ Newbie
 
Registered: Feb 2009
Posts: 3

Rep: Reputation: 0
running two C programs together in linux


i am new to linux OS ...so please help me!!

if i have two programs...
sum.c ----> return (6+4);
diff.c ---> return (7-3);

i want to run diff.c and internally in the background sum.c should also run

can i do so...

plz reply

thanks in advance
puneet
 
Old 02-11-2009, 07:16 AM   #2
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 840

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
I'm not sure that I understand your question right, but
1)sum.c and diff.c are source codes unless you use .c suffix for binaries, so maybe you should compile them first
2)i would suggest to rename your diff program since i believe there already is such a program in linux
3)are these programs supposed to interact with each other somehow?
you can run program with '&' which will run it in the background leaving your shell prompt free if that's what you've meant
 
Old 02-11-2009, 10:51 AM   #3
ehawk
Senior Member
 
Registered: Jul 2003
Posts: 1,257

Rep: Reputation: 48
Do you want to be able to do the instructions of sum.c from within diff.c?

Is this what you mean?

http://en.wikipedia.org/wiki/Header_file
 
Old 02-11-2009, 12:09 PM   #4
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181
I received the top post of this thread by email, apparently from the OP through LinuxQuestions.org
I consider that a serious breach of forum etiquette (I'm not sure whether it is a violation of forum rules).

I make my email available through several forums, because there are situations in which switching a discussion to email is appropriate, and because there are topics on which I am enough of an expert that people should and do email links to forum threads that they think I would have answered in the forum if I had noticed them.

But an unsolicited, nearly nonsense, question from a new forum member on a topic where I haven't demonstrated special expertise doesn't begin to meet the reasons for an email. I would be swamped and need to take my email address out of forums if too many people think that is appropriate.

So if the OP did that as an innocent mistake, please learn not to do such things. If others report that this is some email address harvester rather than just a stupid question, I hope the moderators will take some appropriate action.
 
Old 02-12-2009, 12:19 AM   #5
puneetnepsam
LQ Newbie
 
Registered: Feb 2009
Posts: 3

Original Poster
Rep: Reputation: 0
yeah!!...i want to run sum.c within diff.c

can i do this??

how to compile??
 
Old 02-12-2009, 12:36 AM   #6
puneetnepsam
LQ Newbie
 
Registered: Feb 2009
Posts: 3

Original Poster
Rep: Reputation: 0
sum.c --->
int a=5,b=7;
printf("sum is %d",a+b);


diff.c --->
int a=7,=3;
printf(" difference is %d",a-b)



which i compile...
gcc diff.c
./a.out


the output should be...
difference is 4
sum is 11




how to do this...

thanks in advance
puneet
 
Old 02-12-2009, 12:40 AM   #7
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
  1. Learn to write functions in C.
  2. Learn to use the #include directive.
  3. Write a new program using all I said above.
 
Old 02-12-2009, 07:11 AM   #8
ehawk
Senior Member
 
Registered: Jul 2003
Posts: 1,257

Rep: Reputation: 48
http://www.nada.kth.se/kurser/master...Flecture05.pdf
 
Old 02-12-2009, 07:36 PM   #9
servat78
Member
 
Registered: Jan 2009
Posts: 100

Rep: Reputation: 17
Put the two functions into a single C code file and compile it that way.

Another possibility is to add runtime loading of dynamic libraries to your code, so one the main code would be able to load both of your functions as plug-ins. This is nice, but needs quite some coding to make it work right.

You can also add a statement to your Makefile that compiles both applications and then runs them by triggering the output from one application as input into the other one (like 'app1 | app2').

Debian

Last edited by servat78; 02-19-2009 at 12:22 PM.
 
  


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
running DOS programs under Linux ricstamps Linux - Software 16 04-22-2008 03:02 AM
Running OS X programs on linux Lion-o Linux - General 1 01-20-2007 10:27 PM
Remotely running programs on linux Maverick1182 Linux - Networking 4 10-29-2006 04:24 AM
Running Programs in Linux FrenetiC Linux - Software 6 08-31-2006 05:57 PM
running windows programs on linux im1crazyassmofo Linux - Software 5 01-25-2003 05:03 PM


All times are GMT -5. The time now is 06:42 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