EmbLogic's Blog

sum of two distances using struct and functions

access;
symbols;
locks
root:1.1; strict;
comment @ * @;

1.1
date 2014.03.25.14.53.42; author root; state Exp;
branches;
next ;

desc
@sum of two distances using struct and function
@

1.1
log
@Initial revision
@
text

Posted in Uncategorized | Leave a comment

DIFF BTWN gets(), fgets(), getc(), fgetc() , getchar(), ungetc().

1. All these functions gets(),fgets(),getc(),fgetc(),getchar(),ungetc() …are function is declared in the header file stdio.h.

2.gets() :-it takes single argument.The argument must be a data item representing a string.
gets() doesn’t allow to specify the length of the buffer to store the string in.
This would allow user to keep entering data past the end of your buffer…
Never use gets().Because it is impossible to tell without
knowing the data in advance how many characters gets() will
read, and because gets() will continue to store characters
past the end of the buffer, it is extremely dangerous to
use.
It has been used to break computer security. Use
fgets() instead.

3.fgets():-This function read bytes from stream into the array pointed to by s, until n-1 bytes are read,
or a is read and transferred to s, or an end-of-file condition is encountered.

RETURN VALUE :Both gets() and fgets() return a pointer to the string passed.
and on failure of function gets() and fgets() returns NULL.

4.getc() :-returns a character from the specified file.

5.fgetc():-it’s equivalent to the same getc().Only the implementation of the two functions differs.

6.fgetc() and getc() are equivalent, except that getc may be implemented as a macro in some libraries.

7.getchar():- this is similiar to getc().it return a char form stdin.

8.All these above function getc(),fgetc(),getchar() return EOF on error.

9.ungetc() :-we know how getc() reads the next character from a file stream,this ungetc() is the opposite of getc()
it pushes a character back into the file stream so that it will show up again on the very next read from
the stream, as if you’d never gotten it from getc() in the first place.

Now ,suppose you have a stream of data that you’re reading a character at a time, and you won’t know to
stop reading until you get a certain character, but you want to be able to read that character again
later. You can read the character, see that it’s what you’re supposed to stop on, and then ungetc() it
so it’ll show up on the next read.
The standard only guarantees that you’ll be able to push back one character.
RETURN VALUE:On success, ungetc() returns the character you passed to it. On failure, it returns EOF.

Posted in Uncategorized | Leave a comment

Linux /proc File System

 

/proc is very special in that it is a virtual filesystem. It’s sometimes referred to as a process information pseudo-file system. It doesn’t contain ‘real’ files but runtime system information (e.g. system memory, devices mounted, hardware configuration, etc).Inside the /proc directory, you’ll see two types of content — numbered directories, and system information files. /proc is not a real file system, it is a virtual file system. For example, if you do ls -l /proc/stat, you’ll notice that it has a size of 0 bytes, but if you do “cat /proc/stat”, you’ll see some content inside the file.For this reason it can be regarded as a control and information centre for the kernel. In fact, quite a lot of system utilities are simply calls to files in this directory. For example, ‘lsmod’ is the same as ‘cat /proc/modules’ while ‘lspci’ is a synonym for ‘cat /proc/pci’. By altering files located in this directory you can even read/change kernel parameters (sysctl) while the system is running.

Posted in Character Driver, Device Drivers | Leave a comment

PIPE : IPC mechanism

Pipe is a method of creating the standard output of one process to the standard input of another process.When a process creates a pipe using pipe() system call , the pipe() system call finds the first two available file-descriptors in the process file table and allocates them for reading and writing purposes.pipe() system call returns 0 on success and -1 on failure.

In half duplex pipes , fd[0] and fd[1] are set for reading and writing respectively.The pipe is automatically removed by the operating system when all the processes associated with the pipe terminates.

Certain points which should be kept in mind while implementing pipe:

1.If a process calls read() when the pipe is empty then the process is blocked untill some data is sent through the pipe.

2.If a process calls write() when the pipe is full then the calling process is blocked untill some data is read from the pipe.

3.The process must first call pipe() and then fork().Otherwise the two pipes will be entirely different from each other , i.e parent-child relationship must exist.

Posted in Project 03: Client Server Communication using Linux and IPC | Leave a comment

about RCS

RCS (revision control system) is a project management tool. RCS uses a number of commands to manage source file. It works by tracking source file as its changed by maintaining a single file with list of changes in sufficient detail to recreate the previous version. It also allows you to store comment with every change , which can be very useful to look back in the history of changes that has made to the files. To RCS a file following commands are used.

1.   rcs -i filename

this creates a rcs file with name filenamec,v.

2. ci filename

3 . co -l filename

this locks the previous version of file and allow you to do further changes into it.

 

Posted in Uncategorized | Leave a comment

pipes

Creating “pipelines” with the C programming language can be a bit more involved than our simple shell example. To create a simple pipe with C, we make use of the pipe() system call. It takes a single argument, which is an array of two integers, and if successful, the array will contain two new file descriptors to be used for the pipeline. After creating a pipe, the process typically spawns a new process (remember the child inherits open file descriptors).

SYSTEM CALL: pipe();

PROTOTYPE: int pipe( int fd[2] );
RETURNS: 0 on success
-1 on error: errno = EMFILE (no free descriptors)
EMFILE (system file table is full)
EFAULT (fd array is not valid)

NOTES: fd[0] is set up for reading, fd[1] is set up for writing

The first integer in the array (element 0) is set up and opened for reading, while the second integer (element 1) is set up and opened for writing. Visually speaking, the output of fd1 becomes the input for fd0. Once again, all data traveling through the pipe moves through the kernel.

#include
#include
#include

main()
{
int fd[2];

pipe(fd);
.
.
}

Remember that an array name in C decays into a pointer to its first member. Above, fd is equivalent to &fd[0]. Once we have established the pipeline, we then fork our new child process:

#include
#include
#include

main()
{
int fd[2];
pid_t childpid;

pipe(fd);

if((childpid = fork()) == -1)
{
perror(“fork”);
exit(1);
}
.
.
}

If the parent wants to receive data from the child, it should close fd1, and the child should close fd0. If the parent wants to send data to the child, it should close fd0, and the child should close fd1. Since descriptors are shared between the parent and child, we should always be sure to close the end of pipe we aren’t concerned with. On a technical note, the EOF will never be returned if the unnecessary ends of the pipe are not explicitly closed.

#include
#include
#include

main()
{
int fd[2];
pid_t childpid;

pipe(fd);

if((childpid = fork()) == -1)
{
perror(“fork”);
exit(1);
}

if(childpid == 0)
{
/* Child process closes up input side of pipe */
close(fd[0]);
}
else
{
/* Parent process closes up output side of pipe */
close(fd[1]);
}
.
.
}

Posted in Uncategorized | Leave a comment

how to copy a string in a array..

if we want to insert the elements of a string into a array like

char a[20]=”hello”;

then it will show a error…

because a (array name) is a constant pointer..whose address can not be changed…

and here we try to assign a new address of ‘h’ to the array name..

so we have to use strcpy(built in func) to insert the elements of string in a array….

Posted in Data Structures with C | Leave a comment

linked list

Each element (we will call it a node) of a list is comprising of two items – the data and a reference to the next node. The last node has a reference to null. The entry point into a linked list is called the head of the list. It should be noted that head is not a separate node, but the reference to the first node. If the list is empty then the head is a null reference.

A linked list is a dynamic data structure. The number of nodes in a list is not fixed and can grow and shrink on demand. Any application which has to deal with an unknown number of objects will need to use a linked list.

One disadvantage of a linked list against an array is that it does not allow direct access to the individual elements. If you want to access a particular item then you have to start at the head and follow the references until you get to that item.

Another disadvantage is that a linked list uses more memory compare with an array – we extra 4 bytes (on 32-bit CPU) to store a reference to the next node.

Posted in Uncategorized | Leave a comment

ipc

In computing, inter-process communication (IPC) is a set of methods for the exchange of data among multiple threads in one or more processes. Processes may be running on one or more computers connected by a network. IPC methods are divided into methods for message passing, synchronization, shared memory, and remote procedure calls (RPC). The method of IPC used may vary based on the bandwidth and latency of communication between the threads, and the type of data being communicated.

Posted in Uncategorized | Leave a comment

function pointer

we cannot define a function into a structure, but we can define a function pointer in structure.

Posted in Data Structures with C, Uncategorized | Leave a comment

PIPE

The primitive for creating a pipe is the `pipe’ function.  This creates
both the reading and writing ends of the pipe.  It is not very useful
for a single process to use a pipe to talk to itself.  In typical use,
a process creates a pipe just before it forks one or more child
processes (*note Creating a Process::).  The pipe is then used for
communication either between the parent or child processes, or between
two sibling processes.

The `pipe’ function is declared in the header file `unistd.h’.

Posted in Project 03: Client Server Communication using Linux and IPC | Leave a comment

timing interrupts

the Linux kernel, clocks “tick” slightly different by than they do in the real world. The time does not progress continually, but in increments of 10 ms (milliseconds) each, which is called a tick. This means that the time virtually stands still between any two ticks. The number of ticks since the system started is recorded in a variable called jiffies in the kernel. The timer interrupt increments the jiffies variable at each interrupt. The terms ticks and jiffies are often used interchangeably.

The resolution frequency of the timer interrupt is initialized to the value of the variable HZ (include/asm/param.h), and it increments the jiffies variable every graphics/035fig01.gif.[4] This length of time is absolutely sufficient for normal applications, because a higher interrupt frequency would only mean a higher load on the system due to too many unnecessary interruptions [RuCo01]. However, there are certain situations where a high timer resolution is required, especially to measure smaller time increments or for running actions at specific points in time [WeRi00]. In networks, you often find such requirements for protocol instances, for example protocol instances that have to calculate packet run times or traffic shapers that have to measure minimum time intervals in the microsecond range.

[4] HZ depends on the architecture: In Alpha processors, HZ = 1024; HZ = 100 in most other architectures.

Most of these tasks require clocks with a resolution that is at least in the microsecond range. For example, to implement a traffic shaper [Tane97], you have to calculate the number of bytes that could be sent within a specific interval. For example, the jiffies time measurement with a resolution of 100 Hz is not suitable. With a rate of 2 Mbits/s, an interval of graphics/035fig02.gif already corresponds to a packet with a length of 2500 bytes.

To avoid this problem, most modern processors (Pentium, Alpha, etc.) have appropriate registers. They have been added to those processors mainly to allow system performance measurements and less for traffic shaping in networks. But, while they are present, their use is quite popular. In the Pentium processor and its successors (and most of its clones), this is a 64-bit-wide TSC (Time Stamp Counter) register; its content is incremented by a value of one in each processor clock. The content of this register shows the number of elapsed clock cycles since system start.

The TSC register is actually nothing more than a hardware variant of jiffies, except that its resolutions is higher by a factor of between 106 and 108. This means, for example, that you can measure intervals with an accuracy of 0.001 ms in a Pentium processor with a clock rate of 1 GHz.

Nevertheless, there is a certain inaccuracy when measuring with the TSC register, because it takes a few clocks (approx. ten) to read the register. The reason is the main memory access that occurs after the register value has been read. It can be done only in the bus frequency, which corresponds to a fraction of the CPU frequency. In addition, there could be effects in the first-level and second-level cache accesses that can easily lead to false measurements. However, the error caused by the TSC register is meaningless for normal measurements, because most of them measure only relatively big time cycles (in the 1-ms range). The command get_cycles() (defined in ) can be used to read the content of the TSC register.

Posted in Uncategorized | Leave a comment

mdc

instead of using while,can we use the return value of read untill it returns 0

when it returns 0,it means all the chars in string has been read.

??

Posted in Data Structures with C | Leave a comment

RCS

Name : rcs
Product : Fedora 19
Version : 5.9.0
Release : 1.fc19
URL : http://www.gnu.org/software/rcs/
Summary : Revision Control System (RCS) file version management tools
Description :
The Revision Control System (RCS) is a system for managing multiple
versions of files. RCS automates the storage, retrieval, logging,
identification and merging of file revisions. RCS is useful for text
files that are revised frequently (for example, programs,
documentation, graphics, papers and form letters).

The rcs package should be installed if you need a system for managing
different versions of files.

Posted in Uncategorized | Leave a comment

linklist

The following code inserts a node after an existing node in a singly linked list. The diagram shows how it works. Inserting a node before an existing one cannot be done directly; instead, one must keep track of the previous node and insert a node after it.

CPT-LinkedLists-addingnode.svg
 function insertAfter(Node node, Node newNode) // insert newNode after node
     newNode.next := node.next
     node.next    := newNode

Inserting at the beginning of the list requires a separate function. This requires updating firstNode.

Posted in Uncategorized | Leave a comment