Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3673608
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:45:15+00:00 2026-05-19T02:45:15+00:00

We use strace a lot. We would like to output some text into strace

  • 0

We use strace a lot. We would like to output some text into strace to mark places the code has reached. The way i see people have done it so far is to stat an non-existent file. The filename is just the text they want to see in the strace. Its pretty fast, but I’m sure there is a better way. I worry that there might be a lot of code and maybe kernel locks being hit even though the mount point is bogus. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T02:45:16+00:00Added an answer on May 19, 2026 at 2:45 am

    write() to an out-of-range file descriptor shows up well in strace output, and should be much faster – the range check happens early, and it doesn’t need to look at the data at all. (You need to pass the length of the data to be written, rather than just a 0-terminated string, but gcc will normally optimise strlen() of a constant string to a constant.)

    $ cat hw.c
    #include <stdio.h>
    #include <string.h>
    #include <unistd.h>
    
    #define STRACE_TRACE(str) write(-1, str, strlen(str))
    
    int main(void)
    {
      STRACE_TRACE("before");
      printf("Hello world\n");
      STRACE_TRACE("after");
      return 0;
    }
    $ gcc -Wall -o hw hw.c
    $ strace ./hw
    ...
    write(-1, "before"..., 6)               = -1 EBADF (Bad file descriptor)
    fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 150), ...}) = 0
    mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb77da000
    write(1, "Hello world\n"..., 12Hello world
    )        = 12
    write(-1, "after"..., 5)                = -1 EBADF (Bad file descriptor)
    exit_group(0)                           = ?
    $ 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(please excuse that I didn't use aliases). I would like my query output to
I'd like to know how to use strace to trace system calls in my
I use code belows for dump a specific schema, before dumped it has 4
Use case: 3rd party application wants to programatically monitor a text file being generated
I use rsync to synchronize files to Windows clients in a server agnostic way.
I use a stream reader to import some data and at the moment I
I am trying to use strace -p to attach to an already running JBoss
I'm trying to use strace to monitor all file accesses by g++ but it
I am looking for a tool like ltrace or strace that can trace locally
I'm trying to help a dev of an app I'd like to use trouble

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.