* Switching between foreground and background
@ 2003-09-22 10:48 Silambu Chelvan
2003-09-22 15:37 ` John T. Williams
0 siblings, 1 reply; 14+ messages in thread
From: Silambu Chelvan @ 2003-09-22 10:48 UTC (permalink / raw)
To: linux-newbie
Hi all,
I have written some program with signal handler. Is
this possible, if
one of the signals registered with my program is
raised, my program
should goto background and should come to foreground
when some other of the
registered signal is raised. how to do it?
Any function available to switch a process between
foreground and
background at runtime?
with regards,
M. SilambuChelvan
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Switching between foreground and background
2003-09-22 10:48 Switching between foreground and background Silambu Chelvan
@ 2003-09-22 15:37 ` John T. Williams
2003-09-22 15:51 ` Silambu Chelvan
2003-09-23 11:01 ` Raghuveer
0 siblings, 2 replies; 14+ messages in thread
From: John T. Williams @ 2003-09-22 15:37 UTC (permalink / raw)
To: Silambu Chelvan, linux-newbie
I think part of the problem here might be conceptual.
If I understand what you want, you'd like, on a signal, for your program to
go into the background (still running but no longer blocking the terminal
input/output). On another signal you would like the program to come back to
the foreground.
If this is the case, the problem you're facing is that the program being in
the foreground and the background is actually part of the shell, not a
property of the program running. Most Shells provide a way to switch
programs from the foreground to the background and back.
BASH for example I could type
$>./myprogram
(cntr + Z) //suspends the current program and prings the prompt back
$>bg (runs the program in the background)
The only way that I know of to force a program to run in the background in
the code is to make it a daemon which is done by forking twice
int main( ) {
if(fork()==0) {
if( fork() == 0 ) {
program code starts here
}
exit(0);
}
exit(0);
}
----- Original Message -----
From: "Silambu Chelvan" <silambu_mdu@yahoo.com>
To: <linux-newbie@vger.kernel.org>
Sent: Monday, September 22, 2003 6:48 AM
Subject: Switching between foreground and background
> Hi all,
>
> I have written some program with signal handler. Is
> this possible, if
> one of the signals registered with my program is
> raised, my program
> should goto background and should come to foreground
> when some other of the
> registered signal is raised. how to do it?
>
> Any function available to switch a process between
> foreground and
> background at runtime?
>
> with regards,
> M. SilambuChelvan
>
>
> __________________________________
> Do you Yahoo!?
> Yahoo! SiteBuilder - Free, easy-to-use web site design software
> http://sitebuilder.yahoo.com
> -
> To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.linux-learn.org/faqs
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: Switching between foreground and background
2003-09-22 15:37 ` John T. Williams
@ 2003-09-22 15:51 ` Silambu Chelvan
2003-09-23 11:01 ` Raghuveer
1 sibling, 0 replies; 14+ messages in thread
From: Silambu Chelvan @ 2003-09-22 15:51 UTC (permalink / raw)
To: John T. Williams, linux-newbie
Yes, You have understood what I want. Forcing the
program to run in background is not a problem. I need
to get the program back in foreground.
Do you have any idea?
with regards,
M. SilambuChelvan
--- "John T. Williams" <jowillia@vt.edu> wrote:
> I think part of the problem here might be
> conceptual.
>
> If I understand what you want, you'd like, on a
> signal, for your program to
> go into the background (still running but no longer
> blocking the terminal
> input/output). On another signal you would like the
> program to come back to
> the foreground.
>
> If this is the case, the problem you're facing is
> that the program being in
> the foreground and the background is actually part
> of the shell, not a
> property of the program running. Most Shells
> provide a way to switch
> programs from the foreground to the background and
> back.
> BASH for example I could type
>
> $>./myprogram
> (cntr + Z) //suspends the current program and prings
> the prompt back
> $>bg (runs the program in the background)
>
> The only way that I know of to force a program to
> run in the background in
> the code is to make it a daemon which is done by
> forking twice
>
> int main( ) {
> if(fork()==0) {
> if( fork() == 0 ) {
> program code starts here
> }
> exit(0);
> }
> exit(0);
> }
>
>
> ----- Original Message -----
> From: "Silambu Chelvan" <silambu_mdu@yahoo.com>
> To: <linux-newbie@vger.kernel.org>
> Sent: Monday, September 22, 2003 6:48 AM
> Subject: Switching between foreground and background
>
>
> > Hi all,
> >
> > I have written some program with signal handler.
> Is
> > this possible, if
> > one of the signals registered with my program is
> > raised, my program
> > should goto background and should come to
> foreground
> > when some other of the
> > registered signal is raised. how to do it?
> >
> > Any function available to switch a process between
> > foreground and
> > background at runtime?
> >
> > with regards,
> > M. SilambuChelvan
> >
> >
> > __________________________________
> > Do you Yahoo!?
> > Yahoo! SiteBuilder - Free, easy-to-use web site
> design software
> > http://sitebuilder.yahoo.com
> > -
> > To unsubscribe from this list: send the line
> "unsubscribe linux-newbie" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at
> http://vger.kernel.org/majordomo-info.html
> > Please read the FAQ at
> http://www.linux-learn.org/faqs
>
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: Switching between foreground and background
2003-09-22 15:37 ` John T. Williams
2003-09-22 15:51 ` Silambu Chelvan
@ 2003-09-23 11:01 ` Raghuveer
2003-09-23 16:07 ` John T. Williams
1 sibling, 1 reply; 14+ messages in thread
From: Raghuveer @ 2003-09-23 11:01 UTC (permalink / raw)
To: John T. Williams; +Cc: Silambu Chelvan, linux-newbie
John T. Williams wrote:
>I think part of the problem here might be conceptual.
>
>If I understand what you want, you'd like, on a signal, for your program to
>go into the background (still running but no longer blocking the terminal
>input/output). On another signal you would like the program to come back to
>the foreground.
>
>If this is the case, the problem you're facing is that the program being in
>the foreground and the background is actually part of the shell, not a
>property of the program running. Most Shells provide a way to switch
>programs from the foreground to the background and back.
>BASH for example I could type
>
>$>./myprogram
>(cntr + Z) //suspends the current program and prings the prompt back
>$>bg (runs the program in the background)
>
>The only way that I know of to force a program to run in the background in
>the code is to make it a daemon which is done by forking twice
>
>int main( ) {
> if(fork()==0) {
> if( fork() == 0 ) {
> program code starts here
> }
> exit(0);
> }
> exit(0);
>}
>
>
I don't feel it's required to fork() twice for making it a daemon, once
is enough. Ya, but should use setpgrp() or setpid() and close stdin, out
and err after the fork and go to infinite loop.
-Raghu
>
>----- Original Message -----
>From: "Silambu Chelvan" <silambu_mdu@yahoo.com>
>To: <linux-newbie@vger.kernel.org>
>Sent: Monday, September 22, 2003 6:48 AM
>Subject: Switching between foreground and background
>
>
>
>
>>Hi all,
>>
>>I have written some program with signal handler. Is
>>this possible, if
>>one of the signals registered with my program is
>>raised, my program
>>should goto background and should come to foreground
>>when some other of the
>>registered signal is raised. how to do it?
>>
>>Any function available to switch a process between
>>foreground and
>>background at runtime?
>>
>>with regards,
>>M. SilambuChelvan
>>
>>
>>__________________________________
>>Do you Yahoo!?
>>Yahoo! SiteBuilder - Free, easy-to-use web site design software
>>http://sitebuilder.yahoo.com
>>-
>>To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
>>the body of a message to majordomo@vger.kernel.org
>>More majordomo info at http://vger.kernel.org/majordomo-info.html
>>Please read the FAQ at http://www.linux-learn.org/faqs
>>
>>
>
>-
>To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at http://vger.kernel.org/majordomo-info.html
>Please read the FAQ at http://www.linux-learn.org/faqs
>
>
>
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: Switching between foreground and background
2003-09-23 11:01 ` Raghuveer
@ 2003-09-23 16:07 ` John T. Williams
2003-09-23 16:19 ` guide to inline assembly palash kasodhan
` (2 more replies)
0 siblings, 3 replies; 14+ messages in thread
From: John T. Williams @ 2003-09-23 16:07 UTC (permalink / raw)
To: rvk, John T. Williams; +Cc: Silambu Chelvan, linux-newbie, linux-c-programming
I have to admit that I don't know why, but every resource I've ever read
about causing programs to gain daemon behavior has involved forking 2 times
and then starting the program code. If anyone here does know why, I'd would
be happy to hear it.
----- Original Message -----
From: "Raghuveer" <rvk@gsecone.com>
To: "John T. Williams" <jtwilliams@vt.edu>
Cc: "Silambu Chelvan" <silambu_mdu@yahoo.com>;
<linux-newbie@vger.kernel.org>
Sent: Tuesday, September 23, 2003 7:01 AM
Subject: Re: Switching between foreground and background
> John T. Williams wrote:
>
> >I think part of the problem here might be conceptual.
> >
> >If I understand what you want, you'd like, on a signal, for your program
to
> >go into the background (still running but no longer blocking the terminal
> >input/output). On another signal you would like the program to come back
to
> >the foreground.
> >
> >If this is the case, the problem you're facing is that the program being
in
> >the foreground and the background is actually part of the shell, not a
> >property of the program running. Most Shells provide a way to switch
> >programs from the foreground to the background and back.
> >BASH for example I could type
> >
> >$>./myprogram
> >(cntr + Z) //suspends the current program and prings the prompt back
> >$>bg (runs the program in the background)
> >
> >The only way that I know of to force a program to run in the background
in
> >the code is to make it a daemon which is done by forking twice
> >
> >int main( ) {
> > if(fork()==0) {
> > if( fork() == 0 ) {
> > program code starts here
> > }
> > exit(0);
> > }
> > exit(0);
> >}
> >
> >
> I don't feel it's required to fork() twice for making it a daemon, once
> is enough. Ya, but should use setpgrp() or setpid() and close stdin, out
> and err after the fork and go to infinite loop.
>
> -Raghu
>
> >
> >----- Original Message -----
> >From: "Silambu Chelvan" <silambu_mdu@yahoo.com>
> >To: <linux-newbie@vger.kernel.org>
> >Sent: Monday, September 22, 2003 6:48 AM
> >Subject: Switching between foreground and background
> >
> >
> >
> >
> >>Hi all,
> >>
> >>I have written some program with signal handler. Is
> >>this possible, if
> >>one of the signals registered with my program is
> >>raised, my program
> >>should goto background and should come to foreground
> >>when some other of the
> >>registered signal is raised. how to do it?
> >>
> >>Any function available to switch a process between
> >>foreground and
> >>background at runtime?
> >>
> >>with regards,
> >>M. SilambuChelvan
> >>
> >>
> >>__________________________________
> >>Do you Yahoo!?
> >>Yahoo! SiteBuilder - Free, easy-to-use web site design software
> >>http://sitebuilder.yahoo.com
> >>-
> >>To unsubscribe from this list: send the line "unsubscribe linux-newbie"
in
> >>the body of a message to majordomo@vger.kernel.org
> >>More majordomo info at http://vger.kernel.org/majordomo-info.html
> >>Please read the FAQ at http://www.linux-learn.org/faqs
> >>
> >>
> >
> >-
> >To unsubscribe from this list: send the line "unsubscribe linux-newbie"
in
> >the body of a message to majordomo@vger.kernel.org
> >More majordomo info at http://vger.kernel.org/majordomo-info.html
> >Please read the FAQ at http://www.linux-learn.org/faqs
> >
> >
> >
>
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.linux-learn.org/faqs
^ permalink raw reply [flat|nested] 14+ messages in thread* guide to inline assembly
2003-09-23 16:07 ` John T. Williams
@ 2003-09-23 16:19 ` palash kasodhan
2003-09-23 17:57 ` Progga
2003-09-23 17:24 ` Switching between foreground and background Mariano Moreyra
2003-09-24 14:36 ` gcc : cpp Memory Exhausted Matthew Studley
2 siblings, 1 reply; 14+ messages in thread
From: palash kasodhan @ 2003-09-23 16:19 UTC (permalink / raw)
To: linux-c-programming
Hi
I was looking for a tutorial / guide about mixing C and assembly
code. If some one can point a good guide , that would be great.
palash
^ permalink raw reply [flat|nested] 14+ messages in thread* RE: Switching between foreground and background
2003-09-23 16:07 ` John T. Williams
2003-09-23 16:19 ` guide to inline assembly palash kasodhan
@ 2003-09-23 17:24 ` Mariano Moreyra
2003-09-24 14:36 ` gcc : cpp Memory Exhausted Matthew Studley
2 siblings, 0 replies; 14+ messages in thread
From: Mariano Moreyra @ 2003-09-23 17:24 UTC (permalink / raw)
To: 'John T. Williams', rvk
Cc: 'Silambu Chelvan', linux-newbie, linux-c-programming
I don't know if that's the way to gain daemon behavior. If you fork twice,
your process stills attached to the controlling terminal.
I guess you could finish that terminal session without problem. But I think
that a real daemon has to detach him self from the controlling tty.
You can do that, like Raghu said, calling setpgrp and setsid and closing
stdout an err.
There is also a function in unistd that does all of this for you.
int daemon(int nochdir,int noclose); (see "man daemon")
Don't know if exists in all unix or linux distros. But it seems to work.
Saludos.
Manuk
-----Mensaje original-----
De: linux-c-programming-owner@vger.kernel.org
[mailto:linux-c-programming-owner@vger.kernel.org]En nombre de John T.
Williams
Enviado el: Martes, 23 de Septiembre de 2003 13:07
Para: rvk@gsecone.com; John T. Williams
CC: Silambu Chelvan; linux-newbie@vger.kernel.org;
linux-c-programming@vger.kernel.org
Asunto: Re: Switching between foreground and background
I have to admit that I don't know why, but every resource I've ever read
about causing programs to gain daemon behavior has involved forking 2 times
and then starting the program code. If anyone here does know why, I'd would
be happy to hear it.
----- Original Message -----
From: "Raghuveer" <rvk@gsecone.com>
To: "John T. Williams" <jtwilliams@vt.edu>
Cc: "Silambu Chelvan" <silambu_mdu@yahoo.com>;
<linux-newbie@vger.kernel.org>
Sent: Tuesday, September 23, 2003 7:01 AM
Subject: Re: Switching between foreground and background
> John T. Williams wrote:
>
> >I think part of the problem here might be conceptual.
> >
> >If I understand what you want, you'd like, on a signal, for your program
to
> >go into the background (still running but no longer blocking the terminal
> >input/output). On another signal you would like the program to come back
to
> >the foreground.
> >
> >If this is the case, the problem you're facing is that the program being
in
> >the foreground and the background is actually part of the shell, not a
> >property of the program running. Most Shells provide a way to switch
> >programs from the foreground to the background and back.
> >BASH for example I could type
> >
> >$>./myprogram
> >(cntr + Z) //suspends the current program and prings the prompt back
> >$>bg (runs the program in the background)
> >
> >The only way that I know of to force a program to run in the background
in
> >the code is to make it a daemon which is done by forking twice
> >
> >int main( ) {
> > if(fork()==0) {
> > if( fork() == 0 ) {
> > program code starts here
> > }
> > exit(0);
> > }
> > exit(0);
> >}
> >
> >
> I don't feel it's required to fork() twice for making it a daemon, once
> is enough. Ya, but should use setpgrp() or setpid() and close stdin, out
> and err after the fork and go to infinite loop.
>
> -Raghu
>
> >
> >----- Original Message -----
> >From: "Silambu Chelvan" <silambu_mdu@yahoo.com>
> >To: <linux-newbie@vger.kernel.org>
> >Sent: Monday, September 22, 2003 6:48 AM
> >Subject: Switching between foreground and background
> >
> >
> >
> >
> >>Hi all,
> >>
> >>I have written some program with signal handler. Is
> >>this possible, if
> >>one of the signals registered with my program is
> >>raised, my program
> >>should goto background and should come to foreground
> >>when some other of the
> >>registered signal is raised. how to do it?
> >>
> >>Any function available to switch a process between
> >>foreground and
> >>background at runtime?
> >>
> >>with regards,
> >>M. SilambuChelvan
> >>
> >>
> >>__________________________________
> >>Do you Yahoo!?
> >>Yahoo! SiteBuilder - Free, easy-to-use web site design software
> >>http://sitebuilder.yahoo.com
> >>-
> >>To unsubscribe from this list: send the line "unsubscribe linux-newbie"
in
> >>the body of a message to majordomo@vger.kernel.org
> >>More majordomo info at http://vger.kernel.org/majordomo-info.html
> >>Please read the FAQ at http://www.linux-learn.org/faqs
> >>
> >>
> >
> >-
> >To unsubscribe from this list: send the line "unsubscribe linux-newbie"
in
> >the body of a message to majordomo@vger.kernel.org
> >More majordomo info at http://vger.kernel.org/majordomo-info.html
> >Please read the FAQ at http://www.linux-learn.org/faqs
> >
> >
> >
>
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.linux-learn.org/faqs
-
To unsubscribe from this list: send the line "unsubscribe
linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 14+ messages in thread* gcc : cpp Memory Exhausted
2003-09-23 16:07 ` John T. Williams
2003-09-23 16:19 ` guide to inline assembly palash kasodhan
2003-09-23 17:24 ` Switching between foreground and background Mariano Moreyra
@ 2003-09-24 14:36 ` Matthew Studley
2003-09-24 15:12 ` Matthew Studley
2 siblings, 1 reply; 14+ messages in thread
From: Matthew Studley @ 2003-09-24 14:36 UTC (permalink / raw)
To: linux-c-programming
Hi - I wonder whether anybody can help me?
I'm compiling some code on a robot (Slack 7.0, P 1). I've compiled it many
times before on this platform with no problem. Now when I make I get the
error:
cpp: Memory exhausted
...and the process fails
Anybody got any ideas?
regards
Matt
==============================================
Matthew Studley
The Intelligent Computer Systems Centre
Faculty of Computing, Engineering
and Mathematical Sciences
Coldharbour Lane, Frenchay
BS16 1QY
United Kingdom
tel : 07092 306548
fax : 07092 306548
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: gcc : cpp Memory Exhausted
2003-09-24 14:36 ` gcc : cpp Memory Exhausted Matthew Studley
@ 2003-09-24 15:12 ` Matthew Studley
2003-09-24 22:23 ` Luciano Miguel Ferreira Rocha
0 siblings, 1 reply; 14+ messages in thread
From: Matthew Studley @ 2003-09-24 15:12 UTC (permalink / raw)
To: linux-c-programming
I have 'solved' the problem; I was just compiling one of the source files, I
deleted all compiled output and recompiled all the source. No problem!
This is bizarre!
I have no idea what was causing this though, and would really appreciate any
ideas!
regards
Matt
----- Original Message -----
From: Matthew Studley <matthew.studley@uwe.ac.uk>
To: <linux-c-programming@vger.kernel.org>
Sent: Wednesday, September 24, 2003 3:36 PM
Subject: gcc : cpp Memory Exhausted
> Hi - I wonder whether anybody can help me?
>
> I'm compiling some code on a robot (Slack 7.0, P 1). I've compiled it
many
> times before on this platform with no problem. Now when I make I get the
> error:
>
> cpp: Memory exhausted
>
> ...and the process fails
> Anybody got any ideas?
>
> regards
>
> Matt
>
> ==============================================
> Matthew Studley
>
> The Intelligent Computer Systems Centre
> Faculty of Computing, Engineering
> and Mathematical Sciences
> Coldharbour Lane, Frenchay
> BS16 1QY
> United Kingdom
>
> tel : 07092 306548
> fax : 07092 306548
>
>
>
>
> -
> To unsubscribe from this list: send the line "unsubscribe
linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
>
> This incoming email to UWE has been independently scanned for viruses and
any virus detected has been removed using McAfee anti-virus software
>
>
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: gcc : cpp Memory Exhausted
2003-09-24 15:12 ` Matthew Studley
@ 2003-09-24 22:23 ` Luciano Miguel Ferreira Rocha
0 siblings, 0 replies; 14+ messages in thread
From: Luciano Miguel Ferreira Rocha @ 2003-09-24 22:23 UTC (permalink / raw)
To: Matthew Studley; +Cc: linux-c-programming
On Wed, Sep 24, 2003 at 04:12:54PM +0100, Matthew Studley wrote:
> I have 'solved' the problem; I was just compiling one of the source files, I
> deleted all compiled output and recompiled all the source. No problem!
>
> This is bizarre!
>
> I have no idea what was causing this though, and would really appreciate any
> ideas!
I don't know the exact reason, but I'l give some suggestions:
1. recursive #include, as when a.h #includes "b.h", and b.h #includes "a.h"
or just a.h #includes "a.h"...
2. memory corruption. the compilation of all sources could had caused the
corrupted cache to be discarded.
3. corruption of disk transfers
(by means of an invalid selected DMA or ilegal cable)
Regards,
Luciano Rocha
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Switching between foreground and background
@ 2003-09-22 11:55 Markus Klotzbuecher
2003-09-22 12:38 ` Silambu Chelvan
0 siblings, 1 reply; 14+ messages in thread
From: Markus Klotzbuecher @ 2003-09-22 11:55 UTC (permalink / raw)
To: linux-newbie
On Monday 22 September 2003 12:48 pm, Silambu Chelvan wrote:
> Hi all,
>
> I have written some program with signal handler. Is
> this possible, if
> one of the signals registered with my program is
> raised, my program
> should goto background and should come to foreground
> when some other of the
> registered signal is raised. how to do it?
>
> Any function available to switch a process between
> foreground and
> background at runtime?
Hi
Switching a task between forground and background is nothing else as
suspending and restarting. What i would try to do is, when you get the signal
you want to suspend on, call the pause() function (see pause(2) ). When you
get the signal you want to restart on, just do nothing as this will let the
pause() function return and continue doing what happend before suspend.
Try something like this:
***************************************
#include <signal.h>
#include <stdio.h>
void suspend()
{
printf("Suspending...\n");
pause();
}
void wake()
{
printf("Woken up.\n");
}
int main()
{
signal(SIGUSR1, suspend);
signal(SIGUSR2, wake);
while(1) {
/* do whatever */
printf("doing whatever...\n");
sleep(1);
}
}
Cheers
Markus
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: Switching between foreground and background
2003-09-22 11:55 Switching between foreground and background Markus Klotzbuecher
@ 2003-09-22 12:38 ` Silambu Chelvan
2003-09-22 14:37 ` Markus Klotzbuecher
0 siblings, 1 reply; 14+ messages in thread
From: Silambu Chelvan @ 2003-09-22 12:38 UTC (permalink / raw)
To: linux-newbie
Hi,
Thanks for your information.
The method you suggested works fine but I still have a
requirement. The control is still in the process and
could not see the command prompt. The thing is that I
should get the command prompt whenever the process is
put into background so that I can issue some other
command on the prompt.
Any clues??
with regards,
M. SilambuChelvan
--- Markus Klotzbuecher
<markus.klotzbuecher@creamnet.de> wrote:
> On Monday 22 September 2003 12:48 pm, Silambu
> Chelvan wrote:
> > Hi all,
> >
> > I have written some program with signal handler.
> Is
> > this possible, if
> > one of the signals registered with my program is
> > raised, my program
> > should goto background and should come to
> foreground
> > when some other of the
> > registered signal is raised. how to do it?
> >
> > Any function available to switch a process between
> > foreground and
> > background at runtime?
>
> Hi
>
> Switching a task between forground and background is
> nothing else as
> suspending and restarting. What i would try to do
> is, when you get the signal
> you want to suspend on, call the pause() function
> (see pause(2) ). When you
> get the signal you want to restart on, just do
> nothing as this will let the
> pause() function return and continue doing what
> happend before suspend.
>
> Try something like this:
>
> ***************************************
> #include <signal.h>
> #include <stdio.h>
>
> void suspend()
> {
> printf("Suspending...\n");
> pause();
> }
>
> void wake()
> {
> printf("Woken up.\n");
> }
>
> int main()
> {
>
> signal(SIGUSR1, suspend);
> signal(SIGUSR2, wake);
>
> while(1) {
> /* do whatever */
> printf("doing whatever...\n");
> sleep(1);
> }
> }
>
> Cheers
>
> Markus
> -
> To unsubscribe from this list: send the line
> "unsubscribe linux-newbie" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at
> http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at
http://www.linux-learn.org/faqs
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: Switching between foreground and background
2003-09-22 12:38 ` Silambu Chelvan
@ 2003-09-22 14:37 ` Markus Klotzbuecher
0 siblings, 0 replies; 14+ messages in thread
From: Markus Klotzbuecher @ 2003-09-22 14:37 UTC (permalink / raw)
To: Silambu Chelvan; +Cc: linux-newbie
On Monday 22 September 2003 02:38 pm, Silambu Chelvan wrote:
> Hi,
>
> Thanks for your information.
>
> The method you suggested works fine but I still have a
> requirement. The control is still in the process and
> could not see the command prompt. The thing is that I
> should get the command prompt whenever the process is
> put into background so that I can issue some other
> command on the prompt.
Hi
hmm, I see. You will have to actually stop the process to get the command
prompt, instead of letting it sleep as I suggested earlier. You can do this
by sending the SIGSTOP signal to it:
#include <signal.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
void suspend()
{
printf("Suspending...\n");
pid_t pid = getpid();
kill(pid, SIGSTOP); /*send SIGSTOP to itself */
}
...
The problem arises, when you need to start it again. The stopped process needs
to be sent a SIGCONT signal, which will cause it to continue. Obviously a
stopped process can't catch any signals and can't start itself again. The
only way I see is to have a second process catch the signals and send the
appropriate SIGSTOP and SIGCONT signals to the, lets call it main process.
I hope this helps...
Cheers
Markus
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2003-09-24 22:23 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-09-22 10:48 Switching between foreground and background Silambu Chelvan
2003-09-22 15:37 ` John T. Williams
2003-09-22 15:51 ` Silambu Chelvan
2003-09-23 11:01 ` Raghuveer
2003-09-23 16:07 ` John T. Williams
2003-09-23 16:19 ` guide to inline assembly palash kasodhan
2003-09-23 17:57 ` Progga
2003-09-23 17:24 ` Switching between foreground and background Mariano Moreyra
2003-09-24 14:36 ` gcc : cpp Memory Exhausted Matthew Studley
2003-09-24 15:12 ` Matthew Studley
2003-09-24 22:23 ` Luciano Miguel Ferreira Rocha
-- strict thread matches above, loose matches on Subject: below --
2003-09-22 11:55 Switching between foreground and background Markus Klotzbuecher
2003-09-22 12:38 ` Silambu Chelvan
2003-09-22 14:37 ` Markus Klotzbuecher
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.