![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Using Signals | kapilv | High Level Programming | 2 | 11-28-2008 05:56 AM |
| Threads and Signals | ripunjay | HP-UX | 0 | 04-03-2006 07:21 AM |
| Threads Signals | uday_kumar_spl | High Level Programming | 1 | 11-03-2004 03:44 AM |
| Signals in Shell | UNIX for Advanced & Expert Users | 5 | 03-26-2003 12:31 PM | |
| Signals In HP-UX | kapilv | High Level Programming | 1 | 08-18-2001 10:58 PM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Signals...
(posted this in the scripting forum as well, but figured it should go here) So, what's going on is this:
For our program, we had to create our own shell, and if the user pressed ctrl-c just at the cmdline, then this signal would be ignored, but if there is a foreground process running, let's say, "sleep 10", and ctrl-c was pressed, then this process would be terminated... however, my problem lies within background processes... when I press ctrl-c after running something like "sleep 10 &", where the '&' indicates it's a background process, it uses the correct if branch of my SIGINT_handler, but it terminates the process.... so it's definitely something wrong with either the handler, or the installation of the signal. What I don't get is... if the ctrl-c at the command line doesn't quit the program, why would it terminate my background process? Is it because the parent process just puts the ctrl-c onto the child processes? If so, is there a way to add something to my SIGINT_handler to make it ignore this signal? ****Let me just say that I have successfully been able to ignore the signal for a background process, but this way doesn't use my SIGINT_handler, which I do want it to use so some text gets printed. The way I'm talking of is just using "signal(SIGINT, SIG_IGN)", but like I said, doesn't use my SIGINT_handler... This is my SIGINT_handler: void SIGINT_handler(int sig) { if (foreground_pid == 0) { fprintf(stderr, "\nSIGINT ignored\n"); } else { kill(foreground_pid, SIGINT); foreground_pid = 0; } } And then when I install the handler/signal, I use signal(SIGINT, SIGINT_handler) and also set foreground_pid in its respective spot... so if anyone can help, that'd be awesome, and if you need to see more code or some things are unclear, ask. Thanks. |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|