The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 04-29-2006
Registered User
 

Join Date: Apr 2006
Posts: 22
Question deamonizing

hi folks!
how to deamonize my program,
and also here is a code that my collegue asked me which i could not explain

int main()
{
char **p = &p;
printf("%s\n",*p + 40);
return 0;
}

after compling this gives a warning,
and the output is something out of the sun,can u tell me why it is so.
Reply With Quote
Forum Sponsor
  #2  
Old 04-29-2006
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,326
To answer your questions:
1. How to daemonize your program: this is a very nice explaination of how do that.

2. Regarding the warning: You are getting that cause the program is trying to assign an address (probably an int, definitely numerical) value to a char type of variable. You can write the code as
Code:
char **p=(char**)&p;
and prevent the warning from being thrown.

3. Regarding the output: You are printing an address, which is some random number, as a string. What output are you expecting? Try printing that as an integer.
Reply With Quote
  #3  
Old 04-29-2006
Playing with Ubuntu Now!
 

Join Date: Oct 2005
Location: Chennai
Posts: 364
very good link

That was a very good link blowtorch.
Reply With Quote
  #4  
Old 05-01-2006
Registered User
 

Join Date: Dec 2004
Posts: 8
I think the warning is not because an int type is assigned to a char type ( infact, p when declared as char **p; is definetly not a character variable). The warning comes because of the fact that we are assigning address of a pointer variable to a pointer-to-pointer type variable, and by doing a typecast
Code:
char **p = (char **)&p;
u r typecasting a pointer ( &p) to a pointer-to-pointer ...

Infact, this will also work ...
Code:
char **p = *(&p);
Try doing this on paper with a pen ...

and yes blowtorch, that was a very good link... I too found it useful

Last edited by avdtech; 05-01-2006 at 12:57 AM.
Reply With Quote
  #5  
Old 05-01-2006
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,616
The code shown in that link will allow the deamon to remain a session group leader. If a daemon who is a session group leader opens a tty device without specifying the O_NOCTTY flag, the daemon will un-daemonize itself. That is why I prefer: 1.7 How do I get my program to act like a daemon?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:12 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0