All of lore.kernel.org
 help / color / mirror / Atom feed
* Pause a process execution from external program
@ 2019-06-13  7:43 ` Pintu Agarwal
  0 siblings, 0 replies; 12+ messages in thread
From: Pintu Agarwal @ 2019-06-13  7:43 UTC (permalink / raw)
  To: kernelnewbies, open list, pedro

Hi All,
I was just wondering if this is possible in the Linux world.
My requirement is:
For some reason, I want to halt/pause the execution (for some
specified time) of a running process/thread (at some location),
without modified the source, may be by firing some events/signals from
an another external program, by specifying the address location or a
line number.

Is this possible ?
May be by using some system call, or other mechanism using the process PID.
Assume that its a debugging system with all root privileges.

Basically, its just like how "gdb" is able to set the break-point in a
program, and able to stop its execution exactly at that location.
I am wondering what mechanism "gdb" uses to do this?
I tried to check here, but could find the exact place, where this is handled:
https://github.com/bminor/binutils-gdb/blob/master/gdb/breakpoint.c

Unfortunately, I cannot use "gdb", but I wanted to borrow this
mechanism only to serve my purpose.

If anyone is aware, please let me know.
I will share my findings here, after I get some useful results of my
experimentation.

Thank you for your help!


Regards,
Pintu

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Pause a process execution from external program
@ 2019-06-13  7:43 ` Pintu Agarwal
  0 siblings, 0 replies; 12+ messages in thread
From: Pintu Agarwal @ 2019-06-13  7:43 UTC (permalink / raw)
  To: kernelnewbies, open list, pedro

Hi All,
I was just wondering if this is possible in the Linux world.
My requirement is:
For some reason, I want to halt/pause the execution (for some
specified time) of a running process/thread (at some location),
without modified the source, may be by firing some events/signals from
an another external program, by specifying the address location or a
line number.

Is this possible ?
May be by using some system call, or other mechanism using the process PID.
Assume that its a debugging system with all root privileges.

Basically, its just like how "gdb" is able to set the break-point in a
program, and able to stop its execution exactly at that location.
I am wondering what mechanism "gdb" uses to do this?
I tried to check here, but could find the exact place, where this is handled:
https://github.com/bminor/binutils-gdb/blob/master/gdb/breakpoint.c

Unfortunately, I cannot use "gdb", but I wanted to borrow this
mechanism only to serve my purpose.

If anyone is aware, please let me know.
I will share my findings here, after I get some useful results of my
experimentation.

Thank you for your help!


Regards,
Pintu

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Pause a process execution from external program
  2019-06-13  7:43 ` Pintu Agarwal
@ 2019-06-13  7:52   ` Shyam Saini
  -1 siblings, 0 replies; 12+ messages in thread
From: Shyam Saini @ 2019-06-13  7:52 UTC (permalink / raw)
  To: Pintu Agarwal; +Cc: Kernelnewbies, open list, pedro

Hi Pintu,


> Hi All,
> I was just wondering if this is possible in the Linux world.
> My requirement is:
> For some reason, I want to halt/pause the execution (for some
> specified time) of a running process/thread (at some location),
> without modified the source, may be by firing some events/signals from
> an another external program, by specifying the address location or a
> line number.
>
> Is this possible ?
> May be by using some system call, or other mechanism using the process PID.
> Assume that its a debugging system with all root privileges.
>
> Basically, its just like how "gdb" is able to set the break-point in a
> program, and able to stop its execution exactly at that location.
> I am wondering what mechanism "gdb" uses to do this?

gdb uses ptrace system call, may you can explore ptrace?

> I tried to check here, but could find the exact place, where this is handled:
> https://github.com/bminor/binutils-gdb/blob/master/gdb/breakpoint.c

from command line we use ctrl-z to stop execution of a foreground
process but you can program
SIGTSTP signal handler in your application code to do the same.

is that you want ?

Thanks a lot,
Shyam

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Pause a process execution from external program
@ 2019-06-13  7:52   ` Shyam Saini
  0 siblings, 0 replies; 12+ messages in thread
From: Shyam Saini @ 2019-06-13  7:52 UTC (permalink / raw)
  To: Pintu Agarwal; +Cc: open list, pedro, Kernelnewbies

Hi Pintu,


> Hi All,
> I was just wondering if this is possible in the Linux world.
> My requirement is:
> For some reason, I want to halt/pause the execution (for some
> specified time) of a running process/thread (at some location),
> without modified the source, may be by firing some events/signals from
> an another external program, by specifying the address location or a
> line number.
>
> Is this possible ?
> May be by using some system call, or other mechanism using the process PID.
> Assume that its a debugging system with all root privileges.
>
> Basically, its just like how "gdb" is able to set the break-point in a
> program, and able to stop its execution exactly at that location.
> I am wondering what mechanism "gdb" uses to do this?

gdb uses ptrace system call, may you can explore ptrace?

> I tried to check here, but could find the exact place, where this is handled:
> https://github.com/bminor/binutils-gdb/blob/master/gdb/breakpoint.c

from command line we use ctrl-z to stop execution of a foreground
process but you can program
SIGTSTP signal handler in your application code to do the same.

is that you want ?

Thanks a lot,
Shyam

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Pause a process execution from external program
  2019-06-13  7:52   ` Shyam Saini
@ 2019-06-13 14:53     ` Pintu Agarwal
  -1 siblings, 0 replies; 12+ messages in thread
From: Pintu Agarwal @ 2019-06-13 14:53 UTC (permalink / raw)
  To: Shyam Saini; +Cc: Kernelnewbies, open list, pedro

On Thu, Jun 13, 2019 at 1:22 PM Shyam Saini <mayhs11saini@gmail.com> wrote:
>
> Hi Pintu,
>
>
> > Hi All,
> > I was just wondering if this is possible in the Linux world.
> > My requirement is:
> > For some reason, I want to halt/pause the execution (for some
> > specified time) of a running process/thread (at some location),
> > without modified the source, may be by firing some events/signals from
> > an another external program, by specifying the address location or a
> > line number.
> >
> > Is this possible ?
> > May be by using some system call, or other mechanism using the process PID.
> > Assume that its a debugging system with all root privileges.
> >
> > Basically, its just like how "gdb" is able to set the break-point in a
> > program, and able to stop its execution exactly at that location.
> > I am wondering what mechanism "gdb" uses to do this?
>
> gdb uses ptrace system call, may you can explore ptrace?
>
oh thank you so much.
Yes, ptrace is going to be very helpful. I will explore more on this
and come back if required.

> > I tried to check here, but could find the exact place, where this is handled:
> > https://github.com/bminor/binutils-gdb/blob/master/gdb/breakpoint.c
>
> from command line we use ctrl-z to stop execution of a foreground
> process but you can program
> SIGTSTP signal handler in your application code to do the same.
>
> is that you want ?
>
This required source code modification in the target program, so I
don't want this.

> Thanks a lot,
> Shyam

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Pause a process execution from external program
@ 2019-06-13 14:53     ` Pintu Agarwal
  0 siblings, 0 replies; 12+ messages in thread
From: Pintu Agarwal @ 2019-06-13 14:53 UTC (permalink / raw)
  To: Shyam Saini; +Cc: open list, pedro, Kernelnewbies

On Thu, Jun 13, 2019 at 1:22 PM Shyam Saini <mayhs11saini@gmail.com> wrote:
>
> Hi Pintu,
>
>
> > Hi All,
> > I was just wondering if this is possible in the Linux world.
> > My requirement is:
> > For some reason, I want to halt/pause the execution (for some
> > specified time) of a running process/thread (at some location),
> > without modified the source, may be by firing some events/signals from
> > an another external program, by specifying the address location or a
> > line number.
> >
> > Is this possible ?
> > May be by using some system call, or other mechanism using the process PID.
> > Assume that its a debugging system with all root privileges.
> >
> > Basically, its just like how "gdb" is able to set the break-point in a
> > program, and able to stop its execution exactly at that location.
> > I am wondering what mechanism "gdb" uses to do this?
>
> gdb uses ptrace system call, may you can explore ptrace?
>
oh thank you so much.
Yes, ptrace is going to be very helpful. I will explore more on this
and come back if required.

> > I tried to check here, but could find the exact place, where this is handled:
> > https://github.com/bminor/binutils-gdb/blob/master/gdb/breakpoint.c
>
> from command line we use ctrl-z to stop execution of a foreground
> process but you can program
> SIGTSTP signal handler in your application code to do the same.
>
> is that you want ?
>
This required source code modification in the target program, so I
don't want this.

> Thanks a lot,
> Shyam

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Pause a process execution from external program
  2019-06-13  7:43 ` Pintu Agarwal
  (?)
  (?)
@ 2019-06-13 15:21 ` Elias Kouskoumvekakis
  2019-06-17 12:19   ` Pintu Agarwal
  -1 siblings, 1 reply; 12+ messages in thread
From: Elias Kouskoumvekakis @ 2019-06-13 15:21 UTC (permalink / raw)
  To: Pintu Agarwal; +Cc: kernelnewbies


[-- Attachment #1.1: Type: text/plain, Size: 721 bytes --]

On Thu, Jun 13, 2019 at 10:45 AM Pintu Agarwal <pintu.ping@gmail.com> wrote:
>
> For some reason, I want to halt/pause the execution (for some
> specified time) of a running process/thread (at some location),
> without modified the source, may be by firing some events/signals from
> an another external program, by specifying the address location or a
> line number.
>
> Is this possible ?

Hi Pintu,

have you looked at the CRIU project which can do a checkpoint / restore of
a running process?

https://criu.org/Main_Page

I think it's what you need, although I've never used it myself.

Some other projects and how they compare to CRIU are listed below:

https://criu.org/Comparison_to_other_CR_projects

Best,
Elias

[-- Attachment #1.2: Type: text/html, Size: 1011 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Pause a process execution from external program
  2019-06-13  7:52   ` Shyam Saini
@ 2019-06-13 19:43     ` Valdis Klētnieks
  -1 siblings, 0 replies; 12+ messages in thread
From: Valdis Klētnieks @ 2019-06-13 19:43 UTC (permalink / raw)
  To: Shyam Saini; +Cc: Pintu Agarwal, open list, pedro, Kernelnewbies

[-- Attachment #1: Type: text/plain, Size: 893 bytes --]

On Thu, 13 Jun 2019 13:22:12 +0530, Shyam Saini said:

> from command line we use ctrl-z to stop execution of a foreground
> process but you can program
> SIGTSTP signal handler in your application code to do the same.

Note that if you simply fail to include a signal handler for SIGSTOP and
SIGCONT, it will Do The Right Thing.  The only programs that need worry about
SIGTSTP are ones like 'vi' that may want to do something (like restore the
terminal state from raw to cooked mode, etc) before they stop.  That's why you
can control-z /bin/cat without it having to include a signal handler for it.

% kill -STOP `pidof process-to-stop`   # stop it
% kill -CONT `pidof process-to-stop`  # and make it run again.

No source code modifications needed.  No source needed.

Now, if you want to make it stop at a *specific point*, then you're into
ptrace territory, and source will be helpful.


[-- Attachment #2: Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Pause a process execution from external program
@ 2019-06-13 19:43     ` Valdis Klētnieks
  0 siblings, 0 replies; 12+ messages in thread
From: Valdis Klētnieks @ 2019-06-13 19:43 UTC (permalink / raw)
  To: Shyam Saini; +Cc: Kernelnewbies, Pintu Agarwal, pedro, open list


[-- Attachment #1.1: Type: text/plain, Size: 893 bytes --]

On Thu, 13 Jun 2019 13:22:12 +0530, Shyam Saini said:

> from command line we use ctrl-z to stop execution of a foreground
> process but you can program
> SIGTSTP signal handler in your application code to do the same.

Note that if you simply fail to include a signal handler for SIGSTOP and
SIGCONT, it will Do The Right Thing.  The only programs that need worry about
SIGTSTP are ones like 'vi' that may want to do something (like restore the
terminal state from raw to cooked mode, etc) before they stop.  That's why you
can control-z /bin/cat without it having to include a signal handler for it.

% kill -STOP `pidof process-to-stop`   # stop it
% kill -CONT `pidof process-to-stop`  # and make it run again.

No source code modifications needed.  No source needed.

Now, if you want to make it stop at a *specific point*, then you're into
ptrace territory, and source will be helpful.


[-- Attachment #1.2: Type: application/pgp-signature, Size: 832 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Pause a process execution from external program
  2019-06-13 15:21 ` Elias Kouskoumvekakis
@ 2019-06-17 12:19   ` Pintu Agarwal
  0 siblings, 0 replies; 12+ messages in thread
From: Pintu Agarwal @ 2019-06-17 12:19 UTC (permalink / raw)
  To: Elias Kouskoumvekakis; +Cc: Kernelnewbies

On Thu, Jun 13, 2019 at 8:52 PM Elias Kouskoumvekakis
<eliaskousk@gmail.com> wrote:
>
> On Thu, Jun 13, 2019 at 10:45 AM Pintu Agarwal <pintu.ping@gmail.com> wrote:
> >
> > For some reason, I want to halt/pause the execution (for some
> > specified time) of a running process/thread (at some location),
> > without modified the source, may be by firing some events/signals from
> > an another external program, by specifying the address location or a
> > line number.
> >
> > Is this possible ?
>
> Hi Pintu,
>
> have you looked at the CRIU project which can do a checkpoint / restore of a running process?
>
> https://criu.org/Main_Page
>
> I think it's what you need, although I've never used it myself.
>
OK. Thank you so much I will surely look into it.
Currently, we are exploring using ptrace.

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Pause a process execution from external program
  2019-06-13 19:43     ` Valdis Klētnieks
@ 2019-06-17 12:20       ` Pintu Agarwal
  -1 siblings, 0 replies; 12+ messages in thread
From: Pintu Agarwal @ 2019-06-17 12:20 UTC (permalink / raw)
  To: Valdis Klētnieks; +Cc: Shyam Saini, open list, pedro, Kernelnewbies

On Fri, Jun 14, 2019 at 1:13 AM Valdis Klētnieks
<valdis.kletnieks@vt.edu> wrote:
>
> On Thu, 13 Jun 2019 13:22:12 +0530, Shyam Saini said:
>
> > from command line we use ctrl-z to stop execution of a foreground
> > process but you can program
> > SIGTSTP signal handler in your application code to do the same.
>
> Note that if you simply fail to include a signal handler for SIGSTOP and
> SIGCONT, it will Do The Right Thing.  The only programs that need worry about
> SIGTSTP are ones like 'vi' that may want to do something (like restore the
> terminal state from raw to cooked mode, etc) before they stop.  That's why you
> can control-z /bin/cat without it having to include a signal handler for it.
>
> % kill -STOP `pidof process-to-stop`   # stop it
> % kill -CONT `pidof process-to-stop`  # and make it run again.
>
> No source code modifications needed.  No source needed.
>
> Now, if you want to make it stop at a *specific point*, then you're into
> ptrace territory, and source will be helpful.
>
Yes, I think ptrace can serve our purpose.
Thank you so much.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Pause a process execution from external program
@ 2019-06-17 12:20       ` Pintu Agarwal
  0 siblings, 0 replies; 12+ messages in thread
From: Pintu Agarwal @ 2019-06-17 12:20 UTC (permalink / raw)
  To: Valdis Klētnieks; +Cc: Kernelnewbies, Shyam Saini, pedro, open list

On Fri, Jun 14, 2019 at 1:13 AM Valdis Klētnieks
<valdis.kletnieks@vt.edu> wrote:
>
> On Thu, 13 Jun 2019 13:22:12 +0530, Shyam Saini said:
>
> > from command line we use ctrl-z to stop execution of a foreground
> > process but you can program
> > SIGTSTP signal handler in your application code to do the same.
>
> Note that if you simply fail to include a signal handler for SIGSTOP and
> SIGCONT, it will Do The Right Thing.  The only programs that need worry about
> SIGTSTP are ones like 'vi' that may want to do something (like restore the
> terminal state from raw to cooked mode, etc) before they stop.  That's why you
> can control-z /bin/cat without it having to include a signal handler for it.
>
> % kill -STOP `pidof process-to-stop`   # stop it
> % kill -CONT `pidof process-to-stop`  # and make it run again.
>
> No source code modifications needed.  No source needed.
>
> Now, if you want to make it stop at a *specific point*, then you're into
> ptrace territory, and source will be helpful.
>
Yes, I think ptrace can serve our purpose.
Thank you so much.

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2019-06-17 12:21 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-13  7:43 Pause a process execution from external program Pintu Agarwal
2019-06-13  7:43 ` Pintu Agarwal
2019-06-13  7:52 ` Shyam Saini
2019-06-13  7:52   ` Shyam Saini
2019-06-13 14:53   ` Pintu Agarwal
2019-06-13 14:53     ` Pintu Agarwal
2019-06-13 19:43   ` Valdis Klētnieks
2019-06-13 19:43     ` Valdis Klētnieks
2019-06-17 12:20     ` Pintu Agarwal
2019-06-17 12:20       ` Pintu Agarwal
2019-06-13 15:21 ` Elias Kouskoumvekakis
2019-06-17 12:19   ` Pintu Agarwal

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.