Automatically start stracing process upon invocation The Next CEO of Stack OverflowHow to measure actual memory usage of an application or process?How should strace be used?Starting iPhone app development in Linux?What killed my process and why?How to run Node.js as a background process and never die?How to kill all processes with a given partial name?How to kill a process running on particular port in Linux?Bash script on background: how to kill child processeswhy i dont have right to execute systemtap?Get new pid from nd_syscall.vfork.return in systemtap

Can this transistor (2n2222) take 6V on emitter-base? Am I reading datasheet incorrectly?

Why did early computer designers eschew integers?

Is it possible to make a 9x9 table fit within the default margins?

Creating a script with console commands

Gauss' Posthumous Publications?

Traveling with my 5 year old daughter (as the father) without the mother from Germany to Mexico

Variance of Monte Carlo integration with importance sampling

What does this strange code stamp on my passport mean?

Avoiding the "not like other girls" trope?

Is a linearly independent set whose span is dense a Schauder basis?

Can I cast Thunderwave and be at the center of its bottom face, but not be affected by it?

Prodigo = pro + ago?

How can I prove that a state of equilibrium is unstable?

My ex-girlfriend uses my Apple ID to login to her iPad, do I have to give her my Apple ID password to reset it?

Horror film about a man brought out of cryogenic suspension without a soul, around 1990

Is it possible to create a QR code using text?

Does Germany produce more waste than the US?

How can the PCs determine if an item is a phylactery?

What difference does it make matching a word with/without a trailing whitespace?

Mathematica command that allows it to read my intentions

Can Sri Krishna be called 'a person'?

What does it mean 'exit 1' for a job status after rclone sync

Calculating discount not working

How to find if SQL server backup is encrypted with TDE without restoring the backup



Automatically start stracing process upon invocation



The Next CEO of Stack OverflowHow to measure actual memory usage of an application or process?How should strace be used?Starting iPhone app development in Linux?What killed my process and why?How to run Node.js as a background process and never die?How to kill all processes with a given partial name?How to kill a process running on particular port in Linux?Bash script on background: how to kill child processeswhy i dont have right to execute systemtap?Get new pid from nd_syscall.vfork.return in systemtap










1















The intention of below SystemTap script is to start straceing whenever a process with a given filename is started.



It is called with the following command:



stap -g -v './sstrace.stp' "$PATTERN"


Where PATTERN can for example be mount.



#!/usr/bin/env stap

# Assign command line parameter to the variable.
@define target_filename %( @1 %) # The regex the script will trigger on given as CLI parameter

probe begin
printf( "Probe starting ...n" )
printf( "Try to attach strace upon executing binary (regex) /%s/nn" , @target_filename )


probe end
printf( "Wrapping up ...n" )


probe syscall.execve
if ( filename =~ @target_filename )
start_trace( pid() )



###
### FUNCTIONS
###

function start_trace( pid )
raise( 19 )
# Sleeping is bad practice in SystemTap probe, but don't know how to otherwise
# wait for strace to initialize in time. This will not work as expected when
# workting interactively. Compare these two results while increasing below sleep
# to 1 second.
# $ sudo ./go date
# $ date; echo hi
# $ bash -c 'date; echo hi'
system( sprintf( "strace -f -p %i & sleep 0.01; kill -CONT %i" , pid , pid ) )



The idea is that I stop execution (raise( -19 )) of the target process long enough for strace to attach to the process and, then restarting the target process (kill -CONT $TARGET_PID). This often works, but unfortunately intermittent.



When it works, strace kicks in right after execve(), similar to this:



$ strace date 2>&1 | head
execve("/bin/date", ["date"], 0x7ffeb7ce6430 /* 64 vars */) = 0
brk(NULL) = 0x5578de8fa000 <== strace kicks in here.
access("/etc/ld.so.nohwcap", F_O............


Now the problem I really at least want to understand and hopefully solve, is the fact that on some systems I cannot kill -STOP the target process, it simply throws an error along the lines of: kill: process xyz does not. exist.



I know by the time the execve syscall is called, the PID already exists. What I don't understand is why it doesn't seem to obey the SIGSTOP.



Does anyone know why this happens, how to fix the SystemTap script or have an even smarter way to accomplish the goal starting to trace a process on the fly?










share|improve this question

















This question had a bounty worth +50
reputation from jippie that ended ended at 2019-04-01 19:21:22Z">4 hours ago. Grace period ends in 19 hours


This question has not received enough attention.


Apart from the SystemTap nature of this question, I also want to understand why the describe effect (the process sometimes refusing to SIGSTOP) happens.







migrated from unix.stackexchange.com Mar 21 at 19:26


This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.


















  • on some systems I cannot kill -STOP the target process - do you mean that the issue is absent on some systems while is reproducible in stable manner on other ones? If yes - can you provide more details about system where you face the issue? Linux distribution, kernel version, stap version, etc.

    – Danila Kiver
    Mar 26 at 16:03











  • Just for info: CentOS 7.6.1810, kernel 3.10.0, stap 3.3/0.172 - everything seems to work as expected.

    – Danila Kiver
    Mar 26 at 16:06











  • To help debug this, can you add a call to cat /proc/%i/status after the kill command?

    – Mark Plotnick
    Mar 26 at 16:09












  • @MarkPlotnick Currently it works (of course) ant it shows state: T (stopped). Are you interested in specific fields? I cannot copy/paste from the VM at the moment. Let me give it a few shots try to reproduce the problem.

    – jippie
    Mar 26 at 17:55












  • Trying to reproduce with the cat /proc/%i/status in a while loop ... I'll update when I hit. Usually when it hits once, it stops working for a long time.

    – jippie
    Mar 26 at 18:20
















1















The intention of below SystemTap script is to start straceing whenever a process with a given filename is started.



It is called with the following command:



stap -g -v './sstrace.stp' "$PATTERN"


Where PATTERN can for example be mount.



#!/usr/bin/env stap

# Assign command line parameter to the variable.
@define target_filename %( @1 %) # The regex the script will trigger on given as CLI parameter

probe begin
printf( "Probe starting ...n" )
printf( "Try to attach strace upon executing binary (regex) /%s/nn" , @target_filename )


probe end
printf( "Wrapping up ...n" )


probe syscall.execve
if ( filename =~ @target_filename )
start_trace( pid() )



###
### FUNCTIONS
###

function start_trace( pid )
raise( 19 )
# Sleeping is bad practice in SystemTap probe, but don't know how to otherwise
# wait for strace to initialize in time. This will not work as expected when
# workting interactively. Compare these two results while increasing below sleep
# to 1 second.
# $ sudo ./go date
# $ date; echo hi
# $ bash -c 'date; echo hi'
system( sprintf( "strace -f -p %i & sleep 0.01; kill -CONT %i" , pid , pid ) )



The idea is that I stop execution (raise( -19 )) of the target process long enough for strace to attach to the process and, then restarting the target process (kill -CONT $TARGET_PID). This often works, but unfortunately intermittent.



When it works, strace kicks in right after execve(), similar to this:



$ strace date 2>&1 | head
execve("/bin/date", ["date"], 0x7ffeb7ce6430 /* 64 vars */) = 0
brk(NULL) = 0x5578de8fa000 <== strace kicks in here.
access("/etc/ld.so.nohwcap", F_O............


Now the problem I really at least want to understand and hopefully solve, is the fact that on some systems I cannot kill -STOP the target process, it simply throws an error along the lines of: kill: process xyz does not. exist.



I know by the time the execve syscall is called, the PID already exists. What I don't understand is why it doesn't seem to obey the SIGSTOP.



Does anyone know why this happens, how to fix the SystemTap script or have an even smarter way to accomplish the goal starting to trace a process on the fly?










share|improve this question

















This question had a bounty worth +50
reputation from jippie that ended ended at 2019-04-01 19:21:22Z">4 hours ago. Grace period ends in 19 hours


This question has not received enough attention.


Apart from the SystemTap nature of this question, I also want to understand why the describe effect (the process sometimes refusing to SIGSTOP) happens.







migrated from unix.stackexchange.com Mar 21 at 19:26


This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.


















  • on some systems I cannot kill -STOP the target process - do you mean that the issue is absent on some systems while is reproducible in stable manner on other ones? If yes - can you provide more details about system where you face the issue? Linux distribution, kernel version, stap version, etc.

    – Danila Kiver
    Mar 26 at 16:03











  • Just for info: CentOS 7.6.1810, kernel 3.10.0, stap 3.3/0.172 - everything seems to work as expected.

    – Danila Kiver
    Mar 26 at 16:06











  • To help debug this, can you add a call to cat /proc/%i/status after the kill command?

    – Mark Plotnick
    Mar 26 at 16:09












  • @MarkPlotnick Currently it works (of course) ant it shows state: T (stopped). Are you interested in specific fields? I cannot copy/paste from the VM at the moment. Let me give it a few shots try to reproduce the problem.

    – jippie
    Mar 26 at 17:55












  • Trying to reproduce with the cat /proc/%i/status in a while loop ... I'll update when I hit. Usually when it hits once, it stops working for a long time.

    – jippie
    Mar 26 at 18:20














1












1








1


1






The intention of below SystemTap script is to start straceing whenever a process with a given filename is started.



It is called with the following command:



stap -g -v './sstrace.stp' "$PATTERN"


Where PATTERN can for example be mount.



#!/usr/bin/env stap

# Assign command line parameter to the variable.
@define target_filename %( @1 %) # The regex the script will trigger on given as CLI parameter

probe begin
printf( "Probe starting ...n" )
printf( "Try to attach strace upon executing binary (regex) /%s/nn" , @target_filename )


probe end
printf( "Wrapping up ...n" )


probe syscall.execve
if ( filename =~ @target_filename )
start_trace( pid() )



###
### FUNCTIONS
###

function start_trace( pid )
raise( 19 )
# Sleeping is bad practice in SystemTap probe, but don't know how to otherwise
# wait for strace to initialize in time. This will not work as expected when
# workting interactively. Compare these two results while increasing below sleep
# to 1 second.
# $ sudo ./go date
# $ date; echo hi
# $ bash -c 'date; echo hi'
system( sprintf( "strace -f -p %i & sleep 0.01; kill -CONT %i" , pid , pid ) )



The idea is that I stop execution (raise( -19 )) of the target process long enough for strace to attach to the process and, then restarting the target process (kill -CONT $TARGET_PID). This often works, but unfortunately intermittent.



When it works, strace kicks in right after execve(), similar to this:



$ strace date 2>&1 | head
execve("/bin/date", ["date"], 0x7ffeb7ce6430 /* 64 vars */) = 0
brk(NULL) = 0x5578de8fa000 <== strace kicks in here.
access("/etc/ld.so.nohwcap", F_O............


Now the problem I really at least want to understand and hopefully solve, is the fact that on some systems I cannot kill -STOP the target process, it simply throws an error along the lines of: kill: process xyz does not. exist.



I know by the time the execve syscall is called, the PID already exists. What I don't understand is why it doesn't seem to obey the SIGSTOP.



Does anyone know why this happens, how to fix the SystemTap script or have an even smarter way to accomplish the goal starting to trace a process on the fly?










share|improve this question
















The intention of below SystemTap script is to start straceing whenever a process with a given filename is started.



It is called with the following command:



stap -g -v './sstrace.stp' "$PATTERN"


Where PATTERN can for example be mount.



#!/usr/bin/env stap

# Assign command line parameter to the variable.
@define target_filename %( @1 %) # The regex the script will trigger on given as CLI parameter

probe begin
printf( "Probe starting ...n" )
printf( "Try to attach strace upon executing binary (regex) /%s/nn" , @target_filename )


probe end
printf( "Wrapping up ...n" )


probe syscall.execve
if ( filename =~ @target_filename )
start_trace( pid() )



###
### FUNCTIONS
###

function start_trace( pid )
raise( 19 )
# Sleeping is bad practice in SystemTap probe, but don't know how to otherwise
# wait for strace to initialize in time. This will not work as expected when
# workting interactively. Compare these two results while increasing below sleep
# to 1 second.
# $ sudo ./go date
# $ date; echo hi
# $ bash -c 'date; echo hi'
system( sprintf( "strace -f -p %i & sleep 0.01; kill -CONT %i" , pid , pid ) )



The idea is that I stop execution (raise( -19 )) of the target process long enough for strace to attach to the process and, then restarting the target process (kill -CONT $TARGET_PID). This often works, but unfortunately intermittent.



When it works, strace kicks in right after execve(), similar to this:



$ strace date 2>&1 | head
execve("/bin/date", ["date"], 0x7ffeb7ce6430 /* 64 vars */) = 0
brk(NULL) = 0x5578de8fa000 <== strace kicks in here.
access("/etc/ld.so.nohwcap", F_O............


Now the problem I really at least want to understand and hopefully solve, is the fact that on some systems I cannot kill -STOP the target process, it simply throws an error along the lines of: kill: process xyz does not. exist.



I know by the time the execve syscall is called, the PID already exists. What I don't understand is why it doesn't seem to obey the SIGSTOP.



Does anyone know why this happens, how to fix the SystemTap script or have an even smarter way to accomplish the goal starting to trace a process on the fly?







linux system-calls systemtap






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 18:06







jippie

















asked Mar 20 at 19:04









jippiejippie

46751229




46751229






This question had a bounty worth +50
reputation from jippie that ended ended at 2019-04-01 19:21:22Z">4 hours ago. Grace period ends in 19 hours


This question has not received enough attention.


Apart from the SystemTap nature of this question, I also want to understand why the describe effect (the process sometimes refusing to SIGSTOP) happens.








This question had a bounty worth +50
reputation from jippie that ended ended at 2019-04-01 19:21:22Z">4 hours ago. Grace period ends in 19 hours


This question has not received enough attention.


Apart from the SystemTap nature of this question, I also want to understand why the describe effect (the process sometimes refusing to SIGSTOP) happens.






migrated from unix.stackexchange.com Mar 21 at 19:26


This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.









migrated from unix.stackexchange.com Mar 21 at 19:26


This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.














  • on some systems I cannot kill -STOP the target process - do you mean that the issue is absent on some systems while is reproducible in stable manner on other ones? If yes - can you provide more details about system where you face the issue? Linux distribution, kernel version, stap version, etc.

    – Danila Kiver
    Mar 26 at 16:03











  • Just for info: CentOS 7.6.1810, kernel 3.10.0, stap 3.3/0.172 - everything seems to work as expected.

    – Danila Kiver
    Mar 26 at 16:06











  • To help debug this, can you add a call to cat /proc/%i/status after the kill command?

    – Mark Plotnick
    Mar 26 at 16:09












  • @MarkPlotnick Currently it works (of course) ant it shows state: T (stopped). Are you interested in specific fields? I cannot copy/paste from the VM at the moment. Let me give it a few shots try to reproduce the problem.

    – jippie
    Mar 26 at 17:55












  • Trying to reproduce with the cat /proc/%i/status in a while loop ... I'll update when I hit. Usually when it hits once, it stops working for a long time.

    – jippie
    Mar 26 at 18:20


















  • on some systems I cannot kill -STOP the target process - do you mean that the issue is absent on some systems while is reproducible in stable manner on other ones? If yes - can you provide more details about system where you face the issue? Linux distribution, kernel version, stap version, etc.

    – Danila Kiver
    Mar 26 at 16:03











  • Just for info: CentOS 7.6.1810, kernel 3.10.0, stap 3.3/0.172 - everything seems to work as expected.

    – Danila Kiver
    Mar 26 at 16:06











  • To help debug this, can you add a call to cat /proc/%i/status after the kill command?

    – Mark Plotnick
    Mar 26 at 16:09












  • @MarkPlotnick Currently it works (of course) ant it shows state: T (stopped). Are you interested in specific fields? I cannot copy/paste from the VM at the moment. Let me give it a few shots try to reproduce the problem.

    – jippie
    Mar 26 at 17:55












  • Trying to reproduce with the cat /proc/%i/status in a while loop ... I'll update when I hit. Usually when it hits once, it stops working for a long time.

    – jippie
    Mar 26 at 18:20

















on some systems I cannot kill -STOP the target process - do you mean that the issue is absent on some systems while is reproducible in stable manner on other ones? If yes - can you provide more details about system where you face the issue? Linux distribution, kernel version, stap version, etc.

– Danila Kiver
Mar 26 at 16:03





on some systems I cannot kill -STOP the target process - do you mean that the issue is absent on some systems while is reproducible in stable manner on other ones? If yes - can you provide more details about system where you face the issue? Linux distribution, kernel version, stap version, etc.

– Danila Kiver
Mar 26 at 16:03













Just for info: CentOS 7.6.1810, kernel 3.10.0, stap 3.3/0.172 - everything seems to work as expected.

– Danila Kiver
Mar 26 at 16:06





Just for info: CentOS 7.6.1810, kernel 3.10.0, stap 3.3/0.172 - everything seems to work as expected.

– Danila Kiver
Mar 26 at 16:06













To help debug this, can you add a call to cat /proc/%i/status after the kill command?

– Mark Plotnick
Mar 26 at 16:09






To help debug this, can you add a call to cat /proc/%i/status after the kill command?

– Mark Plotnick
Mar 26 at 16:09














@MarkPlotnick Currently it works (of course) ant it shows state: T (stopped). Are you interested in specific fields? I cannot copy/paste from the VM at the moment. Let me give it a few shots try to reproduce the problem.

– jippie
Mar 26 at 17:55






@MarkPlotnick Currently it works (of course) ant it shows state: T (stopped). Are you interested in specific fields? I cannot copy/paste from the VM at the moment. Let me give it a few shots try to reproduce the problem.

– jippie
Mar 26 at 17:55














Trying to reproduce with the cat /proc/%i/status in a while loop ... I'll update when I hit. Usually when it hits once, it stops working for a long time.

– jippie
Mar 26 at 18:20






Trying to reproduce with the cat /proc/%i/status in a while loop ... I'll update when I hit. Usually when it hits once, it stops working for a long time.

– jippie
Mar 26 at 18:20













0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55287938%2fautomatically-start-stracing-process-upon-invocation%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55287938%2fautomatically-start-stracing-process-upon-invocation%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현