Is the linux thread protected?

Source: Internet
Author: User
Whether linux threads are protected-Linux general technology-Linux programming and kernel information. For details, refer to the following section. In linux, the threads under the same process are in the same process space. Is there any problem of cross-border access?

I just did a test. The answer is: there is a cross-border problem.

[Root @ FC5 thread] # gcc-o hk hookpthread. c-lpthread;./hk; cat hookpthread. c
& A: [b7f77464] ----- a: [20]
& B: [b7576464]
Hook --> & a: [20]
& A: [b7f77464] ----- a: [30]
# Include
# Include
Void * fun (void * I)
{
Int a = 20;
Printf ("& a: [% x] ----- a: [% d] \ n", & a, );
Sleep (1 );
Printf ("& a: [% x] ----- a: [% d] \ n", & a, );
Pthread_exit (NULL );

}

Void * hook (void *)
{
Int B = 10;
Printf ("& B: [% x] \ n", & B );
Printf ("hook --> & a: [% d] \ n", * (& B + 2622464 ));
* (& B + 2622464) = 30;
Pthread_exit (NULL );

}
Int main ()
{
Pthread_t pidfun, pidhook;
Pthread_create (& pidfun, NULL, fun, NULL );
Pthread_create (& pidhook, NULL, hook, NULL );
Sleep (2 );
Return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.