C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 13th, 2003, 09:27 PM
jimo9 jimo9 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 81 jimo9 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 41 sec
Reputation Power: 11
Fork and Send child to background

Hi I want to send a child process to the background, how do I instruct it to? Thanks

Reply With Quote
  #2  
Old April 14th, 2003, 10:11 AM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 6,136 dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 3 Days 21 h 10 m 31 sec
Reputation Power: 1974
I'm trying to understand what you are trying to do. The only way I've heard of for sending a process to the background is from the command line with a "&" , which makes it a job. The only difference that makes, AFAIK, is that a job does not have access to stdin, stdout, or stderr, but it's still in the parent's process group and in the parent's session group -- and its parent is the shell. In other words, sending a process to the background seems to be a shell thing.

However, in doing a Google search I found several hits refering to daemons as "background processes" or "running in the background". Are you trying to make the child process a daemon? Or give it some daemon-like qualities?

In case they cover your problem, here are my notes from the daemon chapter of Kurt Wall's "Linux Programming by Example":

Chapter 9 Daemons (pp 191-200)
1. almost always run with superuser privileges because they provide system services to user programs
2. do not have a controlling terminal (are non-interactive)
3. generally are process-group and session leaders
4. often serve as the process in their group and session
5. its parent is init ($$==1)

Creating a daemon (pp 192-196):
1. fork and make the parent exit
2. create a new session by calling setsid -- gets rid of the controlling terminal
3. make the root directory the working directory (to prevent filesystem problems)
4. set umask to 0, giving daemon free reign to set umask to whatever it wants to
5. close any file descriptors that the child inherited and does not need (eg stdin/stdout/stderr)

example on pp 194-195

NOTE: this way, cannot run the daemon as a user
in order to run it as a user, need to use system logs

Handling Errors (pp 196-200):
need to log errors, etc, to a system log:
<syslog.h>
void openlog(char *ident, int option, int facility);
void closelog(void);
void syslog(int priority, char *format, ...);

OR options for openlog:
LOG_CONS
LOG_NDELAY
LOG_PERROR
LOG_PID

facility is one of:
LOG_AUTHPRIV, LOG_CRON, LOG_DAEMON, LOG_KERN, LOG_LOCAL[0-7], LOG_LPR,
LOG_MAIL, LOG_NEWS, LOG_SYSLOG, LOG_USER, LOG_UUCP

priority is one of:
LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG

example on pp 198-199

Last edited by dwise1_aol : April 14th, 2003 at 10:13 AM.

Reply With Quote
  #3  
Old April 14th, 2003, 12:24 PM
jimo9 jimo9 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 81 jimo9 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 41 sec
Reputation Power: 11
Write your own shell

I am writing my own shell. I have forked the process, and have used the setsid, so I guess that leaves only changing the stdin and stout and sterror. Thanks!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Fork and Send child to background

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap