| pfpietro (7) | |||
|
Hi guys, I'm new on c++ programming and I'm learning how the signal between processes work. (Btw didn't know if I was supposed to post on the beginners forum or in the linux... Admin feel free to move. ) My idea was to create a process and this process would send a signal to his father... But I had no success. I get a bunch of errors and warnings. Here's the code:
Maybe I didn't understand how the signal function works... But as far as I know, to use a handler function I have to create a pointer to that function (in this case void (*hand_pt)(int); ) and assign to this pointer the address of the function that will handle the signal ( hand_pt = &handler; ). Is my line of tought correct ? After that I'd be able to send a signal with the kill() fcn . What am I doing wrong ? Thanks | |||
|
|
|||
| Peter87 (3691) | |||
This part is a bit confusing and I don't think you need it.
If you remove the above lines and change line 30 to signal(SIGUSR1, handler); I think it should work. | |||
|
|
|||
| pfpietro (7) | |
|
Problem solved. The thing was that I needed th declare hand_pt = &handler inside a function and not globally declaring it inside main made it work. Close topic and thanks to peter87 also. ;) | |
|
|
|
| Miven (4) | |||||||
|
Hi guys, forum noob here. I've been poking through the forum to find an answer to a question I have that is very similar to pfpietro's so I thought I'd ask it here instead of starting another topic. Hope this was right. Problem: My sighandler cannot 'see' another function that it needs to call. App.h snippet:
And the problem code snippet from App.cpp:
The error is:
What can I do to make sighandler() 'see' restartApp()? I've tried every permutation I can think of and it just coughs more errors. | |||||||
|
|
|||||||
| Texan40 (446) | |
|
unless sighandler() is a member function of Application wouldn't you need to reference the instance of Application to call restartApp() ? Application myApp; .... myApp->restartApp(); ? | |
|
|
|
| Miven (4) | |||||
|
Thanks for replying so quickly Texan40. I tried that:
And what I got was:
Still mystified. | |||||
|
|
|||||
| kooth (608) | |
|
Hi Miven, Line 79 is complaining about a missing default constructor, which is what you are calling (implicitly) on that line. It should be myApp.restartApp(), since myApp is an object, not a pointer to one. | |
|
|
|
| Miven (4) | |||
|
Hi Kooth. Thank you, but... I tried that and it coughs:
Hey, it didn't complain about the base operand. One less error. I thought this was going to be a simple hack to a half built program, but now I see the code needs a lot of work. I might just rewrite the whole thing in C, using glib and stuff. A nice winter project :) Anyway, some of the code is informative, and obviously a lot of work went into it, so I'll keep it around for reference. A bunch of usable Imlib2 and Xft stuff. To Kooth and Texan40, Thank you for trying. | |||
|
|
|||
| ne555 (4042) | |||
|
_ A method works on an instance of the class. That means that you need to use/modify the status To make it clear
_ To create an instance you need to call some constructor. The problem is that you don't want to create another instance. Because the handler doesn't allow you to pass it as parameter, you will need to make it global. | |||
|
|
|||