![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
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; 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
|
|||
|
|||
|
very good link
That was a very good link blowtorch.
|
|
#4
|
|||
|
|||
|
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; Infact, this will also work ... Code:
char **p = *(&p); 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. |
|
#5
|
||||
|
||||
|
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?
|
||||
| Google The UNIX and Linux Forums |