Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 04-30-2012, 07:27 AM   #1
LQ Newbie
Registered: Feb 2012
Posts: 23
Blog Entries: 1

Rep: Reputation: Disabled
Unhappy Command or function in C to make the process run in background

hi all...
we are trying to make the process run in '&' is used in shell there any command or a function in 'C Programming' that makes a process run in background????

Pleeeeeeease help us

trying from more than a week

Last edited by sowpra; 04-30-2012 at 08:01 AM.
Old 04-30-2012, 08:42 AM   #2
Registered: Apr 2009
Location: Oz
Distribution: slackware64-14.0
Posts: 875

Rep: Reputation: 281Reputation: 281Reputation: 281
This should do the trick :-
man 3 daemon
Old 05-02-2012, 01:45 AM   #3
LQ Newbie
Registered: Feb 2012
Posts: 23

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled

Originally Posted by wildwizard View Post
This should do the trick :-
man 3 daemon

just take a look at this code...!

in shell programming...

it was something like...

echo "Done"
done &

pid = $!
sleep 60 && kill TERM pid

i just tried converting a part of it to C....and i have a problem with that &...!

#include <stdio.h>
#include <sys/types.h>
#include <signal.h>
int kill( pid_t pid, int sig );
int main()
sleep(60) && kill(getpid(),15);

and u told daemon will do that it like within daemon function..this while should be put???

Not getting it
Old 05-02-2012, 01:54 AM   #4
Senior Member
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
Not quite ... read the man page for daemon. The function will fork the program and detach it from the controlling terminal. At that point, the process is and will remain in the background. Anything it does will happen in the background (i.e. you should redirect output and error to files, as you'll no longer have a controlling tty). You might find this page along with the man pages of fork and setsid helpful. This is a bit confusing in C at first (not as easy as in the shell, although behind the scenes the shell is doing the same stuff), so you really need to understand how fork works. In other words, there's no getting around reading some documentation.
Old 05-02-2012, 01:56 AM   #5
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Look at the fork() function. If it returns 0, you are the child. Otherwise it returns the PID of the child.

A daemon is a system program that runs in the background such as sshd. I dont think that is what you are asking about.


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
[SOLVED] Problem with a function having a background process inside a command substitution rylphs Linux - Newbie 2 10-05-2010 11:36 AM
[SOLVED] How does '&' make a process run in background ? Aquarius_Girl Programming 22 12-22-2009 11:58 AM
run c function in the background schneidz Programming 1 09-06-2007 03:05 PM
poepn or system function call executed by a background process kshkid Programming 1 08-24-2006 04:04 AM
how to run any binary in background - background process tej Linux - Newbie 1 08-16-2004 01:27 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:10 PM.

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