working principle of top command in linux [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I want to understand the implementation of top command in linux ie how it uses the procfs interface for displaying the top running processes.?what sources should i refer.

First, read carefully proc(5). Then study code of procps, and, as commented by tangrs, of unixtop, i.e. top-3.7.tar.gz
For example, your program might do
{ FILE* psf = fopen("/proc/self/statm", "r");
if (psf) {
int progsize = 0;
fscanf(psf, "%d", &progsize);
printf ("program size is %d pages\n", progsize);
fclose(psf);
} else perror("fopen /proc/self/statm");
}
to print its own program size. You could make it a function:
int get_my_program_size(void) {
int progsize = -1;
FILE* psf = fopen("/proc/self/statm", "r");
if (psf) {
fscanf(psf, "%d", &progsize);
fclose(psf);
} else perror("get_my_program_size /proc/self/statm");
return progsize;
}
This is really quick: no disk i/o is involved, since the /proc/ filesystem is a pseudo-filesystem and its file contents are computed on the fly and on demand. These pseudo-files (like /proc/1234/statm or /proc/1234/status etc....) should be read sequentially.
If you want user-mode CPU time, you could parse the 14th field (utime) of /proc/self/stat (or of /proc/1234/stat for the process of pid 1234). I leave that as an exercise to the reader....

Related

Book On Making /rdb [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I was told once there is a book that shows you how to make a database from scratch using sed, awk, and the Linux filesystem. I thought I had the name, but now I cannot find it. What is this book called?
Edit:
My understanding is this book was meant for learning how databases work, and how to build your own entirely from scratch using awk and the filesystem. From how it was explained, you could build your own version of /rdb, then when you finished you could just use /rdb itself, but now you'd know how it was made.
So, at the end of the book, you'd have almost completely remade /rdb yourself.
Is it "Unix Relational Database Management: Application Development in the Unix Environment (/RDB)" http://www.amazon.com/exec/obidos/ISBN=013938622X/cbbrownecompu-20/ ?

What is the programming language with syntax like this? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I have some scripts written in proprietary language. I want to know whether there is any language with similar syntax like this ?
PROCEDURE MY_PROC_NAME DO
{
DECLARE VARIABLE ABC AS NUMBER
[ABC] := 123;
IF ([ABC] = 123) THEN
{
WHILE (TRUE) DO
{
}
}
ELSE
{
RETURN
}
#a comment
SomeFunction(123, 456);
CALL ANOTHER_PROCEDURE;
}
Thank you.
That looks a lot like Comal. See http://en.m.wikipedia.org/wiki/COMAL
This is an imperative programming language, with no macro, functional or object-oriented features in the samples provided. It has features borrowed from Pascal (':=') and C ('{}'). The structure is otherwise unremarkable.
There are some distinctive constructs.
PROCEDURE name DO {} to define a procedure (but apparently not a function).
DECLARE VARIABLE name AS type to define a variable.
[ABC] in referring to the contents of a variable.
The lack of a semicolon on the DECLARE line is interesting, but could be a typo.
So, a derivative language probably dating from around the mid to late 1980s. It could even be a dialect of Basic (there were lots of them!).
With some additional code it might be possible to narrow it down further.

I need an executable that does nothing [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Improve this question
How can I create an executable that keeps running and shows up in task manager, but does nothing? I need it for a program, I can use every language, or if it already exists it's better.
Thanks.
Here is a C code to do the job, you can use the thread sleep method to decrease the CPU load
#include<stdio.h>
int main()
{
char a;
while((a=getchar())!='z')// to quit the program when z is pressed
{
}
return 0;
}
Create a file with .cmd extension and write this into that file:
:BEGIN
GOTO BEGIN
You can double click on it, and call it from any programming language you want with this like code:
system("/path_to_your_code/your_file.cmd");
Here's a good example in C#
using System;
using System.Threading;
class Program {
static void Main() {
while(true) {
Thread.Sleep(100); // So we don't spam the CPU too much
}
}
}
Another example for an program you actually could quit without too much hassle.
It just waits for you to press Enter. :)
using System;
class Program {
static void Main() {
Console.ReadLine();
}
}

linux memtester which cover near all physical memory [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I'm looking for a memtester which would cover as large a part as possible of physical memory in a running machine which doesn't have an ECC RAM. It should test memory in chunks. For example: allocate 100MB, test it, release it, allocate another 100MB... I know that some regions of memory are already allocated so kernel has to reallocate them.
I found that this product has an option to specify the physical location but it doesn't work because mmap() function doesn't allocate specified location. I would get the solution if I modified the kernel but that still doesn't solve the problem because some sections are already allocated.
I think that this is a known problem, so is there anyone who already solved it?
Memtest86 is probably the way to go, you can boot it from a ramdisk. We have used it for years to test memory in the factory.
http://www.memtest.org/

I need a binary comparison tool for Win/Linux [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
First of all, I don't need a textual comparison so Beyond Compare doesn't do what I need.
I'm looking for a util that can report on the differences between two files, at the byte level. Bare minimum is the need to see the percentage change in the file, or a report on affected bytes/sectors.
Is there anything available to save me the trouble of doing this myself?
I found VBinDiff. I haven't used it, but it probably does what you want.
I guess it depends on what exactly is contained in the file, but here's a quick one:
hexdump file1 > file1.tmp
hexdump file2 > file2.tmp
diff file1.tmp file2.tmp
Since 16 bytes are typically reported on each line, this won't technically give you a count of the bytes changed, but will give you a rough idea where in the file changes have occurred.
UltraCompare is the best for binary comparison. It has a smart comparator that is really useful.
ECMerge recently introduced a binary differ, it can compare files of several giga bytes (the limit is somewhere above the tera byte). it works on linux, windows, mac os x and solaris.
it gives you byte by byte or block per block statistics.
You can parameter synchronization window (if desired) and minimal match.
You can use xdelta. This is open source binary diff tool that you can use then to make binary patches, but I think it also gives the information about differences found.
There's Araxis Merge available for windows. Here's a page that describes their binary comparison feature.

Resources