LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 05-17-2007, 04:30 AM   #1
knobby67
Member
 
Registered: Mar 2006
Posts: 627

Rep: Reputation: 43
Calling a programme in C.


Hi all,
I need to start a deamon running in my system background before I start up my user code. I was going to run it through a start up script, however thought it might be better to start it up from with in my code. Could anyone advise if this can be done in C.
Thanks
 
Old 05-17-2007, 04:41 AM   #2
nc3b
Member
 
Registered: Aug 2005
Posts: 330

Rep: Reputation: 32
system(), popen() or exec()
 
Old 05-17-2007, 08:58 AM   #3
sibtay
Member
 
Registered: Aug 2004
Location: U.S
Distribution: Ubuntu
Posts: 145

Rep: Reputation: 15
fork() and then exec. man exec, man fork for more details
 
Old 05-19-2007, 11:32 AM   #4
elyk1212
Member
 
Registered: Jan 2005
Location: Chandler, AZ USA
Distribution: Mandrake/Mandriva 10.2
Posts: 186

Rep: Reputation: 30
Yes, however, look at all the details of each method (as mentioned above). A fork then exec will allocate a whole new process memory space and executes a copy of your code with that program counter value at the time of the fork. Kind of like a new thread, but a whole new process memory space. If that is what you want, that is the way to go.
 
Old 05-19-2007, 11:52 AM   #5
sibtay
Member
 
Registered: Aug 2004
Location: U.S
Distribution: Ubuntu
Posts: 145

Rep: Reputation: 15
Quote:
Originally Posted by elyk1212
Yes, however, look at all the details of each method (as mentioned above). A fork then exec will allocate a whole new process memory space and executes a copy of your code with that program counter value at the time of the fork. Kind of like a new thread, but a whole new process memory space. If that is what you want, that is the way to go.
Ofcourse, a new process space will be allocated as a result of fork and then exec would cause that space to be replaced with the daemon's copy. But that is what he wanted right? run a daemon/background *process*.

Thanks
 
Old 05-19-2007, 02:29 PM   #6
kshkid
Member
 
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Rep: Reputation: 30
Quote:
A fork then exec will allocate a whole new process memory space and executes a copy of your code with that program counter value at the time of the fork. Kind of like a new thread, but a whole new process memory space. If that is what you want, that is the way to go.
The copy of code will be executed only till the point there is an exec command.

After executing the exec command, the execution of code is in its own.

And the creation of a thread and to that of a process is completely different.
 
  


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
how to uninstall a programme :) alaios Linux - Software 3 10-09-2006 06:45 PM
sound programme alaios Linux - Software 2 03-09-2006 04:16 AM
How to tell a C++ programme to quit ? yogeshm02 Programming 3 09-09-2005 05:59 AM
odd recursion: calling "by hand" vs calling by cronscript... prx Programming 4 02-12-2005 04:59 PM
how can I modify this programme? wwnn1 Programming 5 05-14-2002 07:55 AM

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

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