LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 01-05-2008, 12:18 PM   #1
karabaja4
LQ Newbie
 
Registered: Jan 2008
Posts: 5

Rep: Reputation: 0
run program in background


hello, i have a question.

is it possible to run a program completely in background without a user seeing anything at all?

lets say i have a program:

[HTML]int main() {
FILE *yay;

yay = fopen("file","w");
while(1) {
printf("woooo!"); //prints to STDOUT
fprintf(yay, "woooo!"); //prints to file
}
return 0;
}[/HTML]

now i want to run this program compiled from console without seeing anything (no stdout). what i want it to do is to print to file without seeing "woooo!" in my console.

i tried something with fork() and close(1) but it didnt work as i expected (in fact it didnt work at all).

so what i am looking for is a command like "program &" but which does not show stdout or stderr of the process.

is there a shell command or a C way to do this?
 
Old 01-05-2008, 12:31 PM   #2
Dinithion
Member
 
Registered: Oct 2007
Location: Norway
Distribution: Slackware 14.1
Posts: 446

Rep: Reputation: 59
You could start it something like this:
command > /dev/null 2>&1 &
(Or direct output to wherever you want)
 
Old 01-05-2008, 12:42 PM   #3
karabaja4
LQ Newbie
 
Registered: Jan 2008
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Dinithion View Post
You could start it something like this:
command > /dev/null 2>&1 &
(Or direct output to wherever you want)
thanks, that's exacly what i was looking for.

one more thing, can u please explain the bold part? i assume it means to redirect stderr to stdout, which is then redirected to /dev/null. correct me if im wrong.

thanks

Last edited by karabaja4; 01-05-2008 at 12:51 PM.
 
Old 01-05-2008, 12:57 PM   #4
Dinithion
Member
 
Registered: Oct 2007
Location: Norway
Distribution: Slackware 14.1
Posts: 446

Rep: Reputation: 59
You are absolutely correct
 
  


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
Running C Program in Background help ibshar Linux - Newbie 7 10-04-2007 02:41 PM
how to run any binary in background - background process tej Linux - Newbie 1 08-16-2004 12:27 AM
Run a program in the background??? KaptinKABOOM Linux - Software 5 07-06-2004 06:40 AM
Program In background frankprogramer Linux - Software 1 10-30-2002 02:56 PM
Telnet to background program Bingwiini Linux - General 0 07-09-2002 09:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:35 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
Open Source Consulting | Domain Registration