LinuxQuestions.org
Visit the LQ Articles and Editorials section
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 09-20-2004, 08:35 PM   #1
feetyouwell
Member
 
Registered: Dec 2003
Location: NC, US
Distribution: Novell Linux Eval (2.6.5)
Posts: 240

Rep: Reputation: 30
code that send a process to the background


What function in C that sends a process to the background?
 
Old 09-20-2004, 09:28 PM   #2
foo_bar_foo
Senior Member
 
Registered: Jun 2004
Posts: 2,553

Rep: Reputation: 51
check out sys/resource.h.
there are a few functions in there dealing with this but the others deal with classes of processes

int nice (int increment);

returned failure is -1
otherwise it returns new nice value
only root processes can lower nice but any thing can raise it (send itself further into background)
default value is 0
the spread of values is set by the kernel but generally
20 is most toward background (or 10)
PRIO_MIN/PRIO_MAX is the spread
negative values are less nice
 
Old 09-20-2004, 09:58 PM   #3
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 58
Code:
/* Jump into background */
  if(fork())
    exit(0);
  setpgrp();
 
Old 09-21-2004, 05:53 PM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
To make a program go really into background, i.e. become a "daemon", you can just call deamon() (see "man 5 daemon")
Code:
#include <stdio.h>
#include <unistd.h>

int main()
{
    if(daemon(0,0) < 0) {
        perror("");
        return 1;
    }

    /* ... */

    return 0;
}
Note that this makes it the program go into background to never come back. It completely detaches from the terminal, and looses stdin, stdout and stderr. It's not what the shell does when ending a command with "&". (or was it that what you were looking for?)

Last edited by Hko; 09-21-2004 at 06:09 PM.
 
Old 11-29-2010, 03:11 PM   #5
ibrahimhab
LQ Newbie
 
Registered: Oct 2010
Posts: 2

Rep: Reputation: 0
Unhappy

hello
pleaze can help me how to send process from frontground to background
and stop by using ctrl+z pleace i need code in
languge c
 
Old 11-29-2010, 03:20 PM   #6
dugan
Senior Member
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 4,765

Rep: Reputation: 1467Reputation: 1467Reputation: 1467Reputation: 1467Reputation: 1467Reputation: 1467Reputation: 1467Reputation: 1467Reputation: 1467Reputation: 1467
http://www.gnu.org/software/libc/man...and-Background
 
  


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
how a father process know which child process send the signal SIGCHLD icoming Programming 10 07-20-2010 07:26 AM
really background a process Henster Linux - Newbie 1 07-01-2005 05:29 AM
is there a system call to send process to run in the background? feetyouwell Programming 4 10-01-2004 04:58 AM
how to run any binary in background - background process tej Linux - Newbie 1 08-16-2004 12:27 AM
send process to background radam Linux - General 6 07-13-2004 04:33 PM


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