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

How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?