How can I change Linux terminal to make it look like the command "top"? - linux

My aim is to make a program using C or C++ that prints to the Linux console in a similar way "top" does, in the sense that top's content updates and changes the existing text in the console, rather than printing new lines. How? I only want to know what are the syscalls or functions that make this possible. A little example would be very much appreciated.

Related

How to detect when a key is press using Linux system calls

I am trying to write a C program that uses Linux system calls to emulate the behaviour of the more command in the Linux terminal. Since the users might enter commands such as q to finish the execution, I am trying to find a way in which to read keystrokes from the standard inout without using read(...), as I don't want the pressed key to appear on the standard output.
In other words, I want to be able to detect pressed keys without them being written.
I have read that ioctl() and the termios struct can somehow be used for this purpose, but I am not sure how they are used (I find the man pages somewhat cryptic).
I have found a few answers to the use of those functions, but all of them seem too complicated. There must be an easier way to detect simple keystrokes, isn't there?
man 3 termios, tcsetattr, disable ECHO on stdin.
For a longer explanation see: Hide password input on terminal
Alternatively, you could go through below termios abstraction, use input layer, /dev/input/*, but I think you'll need to disable forwarding events from your input devices to upper layers then.

linux kernel output in a file

I am using a program by using the linux kernel (in this case a predictor for protein localization). The output/results are printed in the linux kernel, one after each other. However, if I want to copy it to a simple textfile, the "length" of the kernel is not long enough for all the results.
instead of using smaller seperate files, I would like to print the output of the kernel to a file. I tried to google this, but it doesn't really help me futher.
1. dmesg seems to be for system-output stuff?
2. the /var/log/syslog.txt doesn't show the stuff I need, but other technical kernel stuff.
3. i saw something with printf(), but didn't quite understand the mechanics and if it was useable for my problem.
could someone explain how to do this or where to look for the right info?
I think i found out how to do it, by using > fileToBeNamed.txt at the end of the command, Sorry :(

simple keyboard event handler in D

I am trying to make a simple keypress handler that I can recycle into any program I'd like to make in D. In my search I can only really find information on how to do this in C, namely by using getch() to read characters from the command line input buffer. But I don't neccessarily want to run a program on the command line. Much like every other program in existence. I've been looking everywhere for this, even on Dlang.org , and haven't found a satisfactory answer yet.
In my specific case I'm trying to make a simple game as a project to help me learn D and I realized that I needed keypress handling so I could, at the very least, navigate menus I'd create in a more natural way so I could properly test my game.
I would eventually like this system to be usable on both windows and linux interchangably, probably just by detecting the operating system the program is running on at launch and then choosing the right code to run to make it all work. But that will come later. Right now i just want to know how to build a simple Keypress event handler that can trigger a function or method or whatever I want as soon as I press the key and have it work in a windows environment.

How to create a running process graph in Linux

Basically, I need to draw a graph over all running Linux Processes.
I followed below step's but looking out some best solution for this work.
Using Top command get all running process and redirect to a file, next then extract input from given file and draw Graph using some programming API.
This step's seem to be very tedious, Is there any other way to do this work in Linux itself. Please give a suggestion.
You should investigate the /proc filesystem, it has the information you need in a matter that is easily accessible to a perl script.
There is some documentation available at http://www.tldp.org/LDP/Linux-Filesystem-Hierarchy/html/proc.html
Of special interest to you is the "children" meta file, there is some documentation at https://lwn.net/Articles/475688/

Google Chrome over Linux FrameBuffer

I am working on a project where I need to run Google chromium over Linux FrameBuffer, I need to run it without any windowing system dependency ( It should draw on the buffer we provide it to draw, this will make its porting to any embedded system very easy) , I do not need its multi-tab GUI, I just need its renderer window in the buffer, has any body ever tried this? Any help on what approach should I use for this?
If you need to have some direct control of the window functions, or want to poke around in the DOM data, then the right way to solve this problem is to probably look at embedding webkit directly. This will be much faster and cleaner than what I am about to suggest.
Now, let's suppose you don't need all that fancy control and that you are really lazy. An ancient, low tech solution to your problem could be to create a virtual frame buffer and then read its contents directly. To do this, you can set up xvfb on your server:
http://www.x.org/releases/X11R7.6/doc/man/man1/Xvfb.1.xhtml
xvfb is an old unix tool that lets you create a virtual x-server with whatever type of configuration you want. More importantly, it can be configured to write the contents of its X server's screen directly to a memory mapped file! You can also set it up to use shared memory, which is a bit faster though also more complicated.
I guess you will have better luck with uzbl and GTK/DirectFB. Same engine, and works with javascripts. For the facebook chat issue, I think you just have to change the user-agent string.
There is the Origyn Web Browser, which is supposed to be an embedded WebKit-based browser that looks portable and does not depend on "heavy" libraries (like GTK). Their web page is http://www.sand-labs.org/owb but it looks like their database crashed, which is a little worrying maybe.
try to port webkit engine to the netsurf framebuffer-based code.
HTH
You could buy one of the remaining 10 (or so) OGD1 boards.
http://en.wikipedia.org/wiki/Open_Graphics_Project
Then you can talk directly to hardware using libpci.
However you will still need code that draws a picture into a memory buffer.
I realize this answer is more a shameless plug.
But people who are interested in your question might want such a board.
I already have a board like this and it would help a lot if it got more exposure.
This project:
http://code.google.com/p/wkhtmltopdf/
Achieves that. It runs Webkit on a virtual display and captures the rendered output in form of PDF. You can customize that do do something else.
OR you can create a display with tigthvnc, and set DISPLAY variable so that Chrome renders in that display.
I suggest using the webkit2pdf package (which is available for many different Linux distributions). Then use fbgs which is a wrapper for the fbi frame buffer program, that displays PDF files right on the frame buffer.

Resources