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 8161097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:25:28+00:00 2026-06-06T18:25:28+00:00

I’ve been writing a program trying to find itself using the procps library. But

  • 0

I’ve been writing a program trying to find itself using the procps library.
But for some reason it smashes the stack.
This is my code:

int main(){
    PROCTAB *ptp;
    proc_t task;
    pid_t mypid[1];
    mypid[0] = getpid();
    printf("My id: %d\n", mypid[0]);
    ptp = openproc(PROC_PID, mypid, 1);
    if(readproc(ptp, &task)){
        printf("Task id:%d\n",task.XXXID);
    }
    else{
        printf("Error: could not find currect task\n");
    }
    closeproc(ptp);
    printf("Done\n");
    return 0;
}

The output i get when i run the program is:

$ ./test 
My id is: 8514
Task id is:8514
Done
*** stack smashing detected ***: ./test terminated
======= Backtrace: =========
/lib/i386-linux-gnu/libc.so.6(__fortify_fail+0x45)[0xb7688dd5]
/lib/i386-linux-gnu/libc.so.6(+0xffd8a)[0xb7688d8a]
./test[0x804863e]
/lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xf3)[0xb75a24d3]
./test[0x80484f1]
======= Memory map: ========
...
Aborted (core dumped)

Any one has an idea why it happens?
Am I doing something wrong?
Thanks.

Edit:
I’ve looked at the header file and notice that I’ve made a wrong use of the openproc function the correct way to use it is (for pid) is to have the mypid array be null terminated, so I’ve change my code to:

int main(){
    PROCTAB *ptp;
    proc_t task;
    pid_t mypid[2];
    mypid[0] = getpid();
    memset(&mypid[1], 0, sizeof(pid_t));
    printf("My id: %d\n", mypid[0]);
    ptp = openproc(PROC_PID, mypid);
    if(readproc(ptp, &task)){
        printf("Task id:%d\n",task.XXXID);
    }
    else{
        printf("Error: could not find currect task\n");
    }
    closeproc(ptp);
    printf("Done\n");
    return 0;
}

and it still crushes the stack.

  • 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-06-06T18:25:28+00:00Added an answer on June 6, 2026 at 6:25 pm

    It works for me here. After getting that version of procps, it compiled and run fine:

    $ gcc -Wall -Werror -o rp -L. -lproc-3.2.8 rp.c
    $ ./rp
    My id: 11468
    Task id:11468
    Done
    

    Update

    Try a modified version:

    proc_t *result;
    ...
    if((result = readproc(ptp, NULL))){
        printf("Task id:%d\n",result->XXXID);
        free(result);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.