Hi Muli,
Thanks for the code I should have myself wrote. I found that for
whatever reason I don't know, killall -SIGSTOP and killall
-SIGCONT both send SIGTERM! Using killall -19 and killall -18
fixed the problem.
Behdad
On Tue, 19 Aug 2003, Muli Ben-Yehuda wrote:
> On Tue, Aug 19, 2003 at 02:20:49PM +0430, Behdad Esfahbod wrote:
>
> > Hi,
> >
> > How to stop a process from a shell script (or C code)? I mean
> > like pushing Ctrl+Z. When I try kill -STOP pid, the process
> > terminates. 'strace bash' didn't helped. It makes lots of
> > sigaction calls that I can't understand what they are.
>
> Hi Behdad,
>
> Take a look at this program:
>
> #include <stdio.h>
> #include <unistd.h>
> #include <stdlib.h>
> #define __USE_GNU
> #include <signal.h>
>
> void sighandler(int signum)
> {
> printf("caught %d\n", signum);
> }
>
> int main(void)
> {
> int i;
> sighandler_t ret;
> printf("setting sighandlers: \n");
>
> for (i = 1; i < SIGRTMIN; ++i) {
> if ((ret = signal(i, &sighandler)) == SIG_ERR) {
> /* some signals can't be caught */
> if (i == SIGKILL || i == SIGSTOP)
> continue;
>
> printf("signal(%d) failed\n", i);
> exit(EXIT_FAILURE);
> }
> }
>
> printf("sighandlers set.\n");
>
> while(1)
> getchar();
>
> return 0;
> }
>
> Compile and run it, you'll see that when you hit C-z, the shell
> actually sends SIGTSTP (20), not SIGSTOP(19).
>
> > Moreover, how to start such a stopped process? 'kill -CONT pid'
> > does not work on a process stopped by (the same) bash. BTW,
> > strace showed that bash itself do call a kill -CONT.
>
> kill -CONT should work, I don't know why it doesn't. Perhaps it does,
> but you are confusing the shell's job control facilities, which still
> show it as stopped? it should be pretty easy to check.
>
--
Behdad Esfahbod 29 Mordad 1382, 2003 Aug 20
http://behdad.org/ [Finger for Geek Code]
If you do a job too well, you'll get stuck with it.
=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]