deamonizing


 
Thread Tools Search this Thread
Top Forums Programming deamonizing
# 1  
Old 04-29-2006
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.
# 2  
Old 04-30-2006
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.
# 3  
Old 04-30-2006
very good link

That was a very good link blowtorch.
# 4  
Old 05-01-2006
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 ... Smilie

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 Smilie

Last edited by avdtech; 05-01-2006 at 04:57 AM..
# 5  
Old 05-01-2006
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?
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question