Showing posts with label strace. Show all posts
Showing posts with label strace. Show all posts

Tuesday, June 14, 2016

Python linked list

If you are planning to refresh your data structure knowledge, I would recommend this website http://www.geeksforgeeks.org/data-structures/

Tree or Linked list datastructure  programming heavily use the recursion concept ... recursion is something that sometimes cause me brain crash :-)

But once you understand it and learn how to use recursion , then that is where you start mastering datastructure concepts.

If you look at Tree or linked list, it is a repetition of a node or a same structure(http://quiz.geeksforgeeks.org/binary-tree-set-1-introduction/)   .. so when there is repetition of something, then there is always scope for recursion concepts to apply...

Python Linked List:

Python programming language also have OOP concepts. So that means we can define a class http://www.diveintopython.net/object_oriented_framework/defining_classes.html

You can go through the linked list details in the below link
http://quiz.geeksforgeeks.org/linked-list-set-1-introduction/ . You will see two classes they defined for implementing linked list.

I was just trying to build without 2 classes. We can build a linked list, I dont know why they used 2 classes..I am not sure on how python is doing this dynamic memory allocation.



Program:



Strace:


Monday, June 13, 2016

Strace on a tree structure C program

When I tried to access 'unallocated node value' , as usual 'Segmentation fault' came as output :-)

But i am not fully clear on how mmap() system call allocate the memory...

I also came to know that mprotect() system call sets the protection,

If the calling process tries to access memory in a manner that violates the protection, then the kernel generates a SIGSEGV signal for the process.

Program and Strace details:



 
 
 

Thursday, June 2, 2016

Try Strace on wget command

Its fun to try Strace on different commands to see what actually happens behind the command. There are some very good options to filter out required systems calls from the log.
The following link gives examples on how to use Strace http://www.thegeekstuff.com/2011/11/strace-examples/

one interesting system call is 'select' . I was only heard about 'select' in sql queries,but this is a different place i am seeing select :-)

"select() and pselect() allow a program to monitor multiple file descriptors, waiting until one or more of the file descriptors become "ready" for some class of I/O operation (e.g., input possible). A file descriptor is considered ready if it is possible to perform a corresponding I/O operation"



The sigaction() system call is used to change the action taken by a process on receipt of a specific signal.



 socket system call:


Tuesday, May 31, 2016

Strace experiments on Python

I was watching the video on 'Type  Python ,Press enter. What happens'. I thought of checking whether 'strace' can get the fork() system call that he explained in the video.

Unfortunately I couldn't get ....



But i came to know about the write and read system calls when we type the arithmetic operatons on python ... strace log pasted below. Still I dont know where the calculation is happening.... is there any tool to list which part is calculating it ? where is the fork() ?? brk(0x19ed000) = 0x19ed000 ioctl(0, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B38400 opost isig icanon echo ...}) = 0 ioctl(1, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B38400 opost isig icanon echo ...}) = 0 write(2, ">>> ", 4) = 4 read(0, "1+2\n", 1024) = 4 fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 6), ...}) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f0206e7b000 write(1, "3\n", 2) = 2 ioctl(0, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B38400 opost isig icanon echo ...}) = 0 ioctl(1, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B38400 opost isig icanon echo ...}) = 0 write(2, ">>> ", 4) = 4 read(0, "1+4\n", 1024) = 4 write(1, "5\n", 2) = 2 ioctl(0, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B38400 opost isig icanon echo ...}) = 0 ioctl(1, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B38400 opost isig icanon echo ...}) = 0 write(2, ">>> ", 4) = 4 read(0,