vfork – the Faster fork
I came across an interesting alternative for the good old fork: vfork.
Lets see a simple process creating example:
#include <stdio.h>
int main()
{
switch (fork())
{
case -1:
printf("Failed to create new process\n");
return -1;
case 0:
printf("Child running\n");
execvp(.. load child ...)
break;
default:
printf("Parent running\n");
wait();
break;
}
return 0;
}
This is the most common process creating pattern. Now what does fork do? It creates a child as an exact parent copy, with the same file descriptors, same stack, same stack and data segments. But most of the times, immediately after fork, the child will load a new image: its own code. So why do we need all the exact fork does?
For child processes that need to start as fast as possible, the solution is vfork: it creates the child without copying the parent segments. So faster. But safer?.. The trick here is that using vfork the child will share the file descriptors, the data, stack and text with the parent until it will load its own image. So any changes in the child will imediately affect the parent.
Here’s a short example:
#include <stdio.h>
int a = 1;
int main()
{
switch (vfork())
{
case -1:
printf("Failed to create new process\n");
return -1;
case 0:
printf("Child running\n");
a = 2 *a;
execvp(... child...);
break;
default:
sleep(1);
printf("Parent running - %d\n", a);
wait();
break;
}
return 0;
}
The output:
Child running
Parent running - 2
So use it, but use it wisely!
Developing Graphical User Interfaces in Linux
Currently, I’m working on my graduation diploma. I have to add zero-config capabilities to an already existing vpn solution: Open Vpn. I said to myself it would be nice to add a graphical interface (GUI) to the whole thing, make it more Windows style. So I’ve done some research in this areas. I found two solutions for developing user interfaces in Linux:
- Qt – is is a crossplatform toolkit used for developing GUI used, for exmaple, with KDE, Opera or Skype. It uses C++ and offers bindings for languages such as Pascal, Php, Ruby or Phyton. It can be used an all major platforms. I personally loved it and found it very intuitive and Java-like (the naming helps a lot).
For documentation, I used C++ GUI Programming with Qt 4, 2nd Edition, Prentice Hall. - Gtk is developed in C, with bindings for C++, Java, C#, Php, Python and others. All thought it was designed for X11, it can run also in Windows environments. I found it difficult to use, with very few examples online andwith very few relevand documentation sources. I used Foundations of GTK+ Development, Apr. 2007, Apress.
I think more relevant would be to offer some examples. So let’s se how the classical “Hello World!” looks with both Qt and Gtk.
For now, the Qt versions. I personally enjoyed working work Qt, I find it very simillar to Java – the OOP helps a lot. The main probleme: there is no Qt binding for C. VLC has solved this probleme: they have the GUI in Qt and the “functionalities” in C. But the process is difficult and for small projects, I don’t think it worths considerring manual binding.
Qt Hello World
First thing to notice is that everything in Qt is a widget – this is the base clase. Of course, there is also the QObject class, but we are concerned with graphical objects.
#include <QApplication> #include <QMainWindow> #include <QLabel> #include <QPushButton> #include <QHBoxLayout> int main(int argc, char *argv[]) { QWidget *mainWindow = new QWidget; QPushButton *okButton; QLabel *helloLabel; QApplication app(argc, argv); // Set window properties mainWindow->setWindowTitle("Say Hello Back!"); mainWindow->setFixedHeight(175); mainWindow->setFixedWidth(200); mainWindow->move(800, 150); // Create a horizontal box for holding the content QHBoxLayout *lh = new QHBoxLayout; // Create the label and the button helloLabel = new QLabel("Hello World!"); okButton = new QPushButton("Bye"); okButton->setFixedSize(100, 30); // An an "action handler" for the button QObject::connect(okButton, SIGNAL(clicked()), &app, SLOT(quit())); // Add content to the layout box lh->addWidget(helloLabel); lh->addWidget(okButton); // Set the window's layout mainWindow->setLayout(lh); // Show the window mainWindow->show(); return app.exec(); }
Qt offert a tool for creating projects and generating makefile: qmake. To obtain an executable from the above example:
// It creates a project - // the name is given by the directory's name >qmake -project // Generate Makefile >qmake --makefile // Compile sources make // Run.... ./<ProjectName>
The result for the above example:

Qt Sample Screenshot
Tinkle, Twinkle Little Star Shaped Form
C# offers an interesting option for creating forms with more unusual shapes. So no more rectangles or square. We can create any kind of shapes for our forms. How? By setting the form’s Region property at load time. But there is a drawback: the classical close, minimize or help button might by out of the region we’ve defined, so the user can’t see them. The solution: draw these button manually and implement the correspondint functionality. It is a good practice to set the form’s FormBorderStyle property to None, to prevent some ugly randerring.
First, let”s define the region. These is done in Form_Load event handler. Simply duble click the form and the handler will be automatically added. So to create a new region, use something similar to the following lines of code:
// Create a graphical path, containing the points that describe // the desired form GraphicsPath gp = new GraphicsPath(); gp.AddPolygon(new Point[] { new Point(220, 17), new Point(280, 100), new Point(380, 100), new Point(350, 200), new Point(420, 270), new Point(320, 300), new Point(310, 400), new Point(220, 360), new Point(130, 400), new Point(120, 300), new Point(20, 270), new Point(90, 200), new Point(60, 100), new Point(160, 100) }); // Set the form's region to the already defined graphical path this.Region = new Region(gp);
This code defines a star form. The result can be seen in the following screenshot. The buttons for close, minimize and help have been placed manually.

Custom form shape demo
LAN Ip Scanner
Recently I came across a useful network API provided by Microsoft: Ipapi – IP Helper API. I’ve wrote a small application using it and I’ve explain here what is the purpose of Ipapi.
What is Ipapi?
Ipapi is an API provided by Microsoft for network programming. The official page on MSDN is:
http://msdn.microsoft.com/en-us/library/aa366073(VS.85).aspx
It is destinated for C/C++ programmers. Ipapi provides the neccesary functions, procedures and structures to get information about the network configurations and change them. There are available several types of operations:
- retrieving information about network configuration
- managing network adapters, interfaces and IPs
- using ARP
- using ICMP
- routing
- get notification for network events
- get information about TCP and UDP
Example 1: get information about network adapters (more…)
PKI Basics
Due to the fact that “the bad guys” appeared quickly on the web and in networks, generally speaking, some things had to be done to make the web a safer place. One of this things is SSL – Secure Socket Layer.
What is SSL?
SSL is a security protocol, that works on a TCP/IP data stream. Used with HTTP at application level, the result is HTTPS – that is HTTP secure. SSL is used to secure the communication between to entities, such as a client and a server, by encrypting the data send between them. Usually, only the server needs to authenticate, so the client is sure to whom is is communicating. To get even more secure, both entities must authenticate. At this point A Public Key Infrastructure – or PKI – is required, unless the client uses TLS-PKS or Secure Remove Password protocols. So SSL ensures secure communication accross Internet.
SSL phases
Usually, when a client and a server communicate using SSL, some steps must be followed:
- negotiate the encryption details – the “handshake” – such as the cipher or authentication codes
- exchange keys and authentication – usually using public key algorithms
- exchange data using the already agreed on encryption algorithm
So at phase two the server and the client must authenticate each other. If, for example, the client receives the server’s authentication details, how can it establish that the server really is who it claims it is? Well, this is done using PKI.
VANET
These days I am going to chose a topic for my graduation paper. Right now one of my options is “Message Passing Protocol for VANET using geographical data”. I’ve read about this topic a lot tonight and I found it quite interesting and with immediate practical application. So I’ve put together a short presentation about VANETs.
VANET (Vehicular ad-hoc newtork)
Definition
VANETs are a form of mobile ad-hoc networks destinated to ensure communication between passengers inside a vehicle, between vehicles or between vehicles and fixed equipment, known as roadside equipment. To ensure connectivity, nowdays a small electronic device is places inside the vehicle. It’s purpose is to ensure connectivity for the pessengers without a server or any complicated configuration settings. Using this device, the vehicle becomes a node in an ad-hoc network. Besides the regular Internet connectivity, VANETs can assure some additional services, such as traffic information.
Due to the fact that the vehicles are continously moving, VANETs have the same problems like MANs, but in VANETs the vehicles must follow a given road, some some adjustments can be made in order to improve the communication in VANETs.
An advanced form of VANETs are Intelligent VANET (InVANET), that uses a great range of modern solution in order to offer the best performance for VANETs: implementations for 802.11b/g, WiMax 802.16, Bluetoth or ZigBee.
MPI – Getting started
Last year I had a distributed systems course. This year, we take it a little bit further and I have another course: programming for distributed systems. Currently, I am studying at school one of the possible way of communication in a distributed system: message passing. One of the most important standards of message passing communication is MPI (Message Passing Interface).
MPI is a language independent standard. It brings portability, scalability and high performance. Currently, one of the most important MPI implementation is mpich.
One of the problems I’ve been confronted to was hot to install MPI. I consider the followig document to be extremely useful (I’ve tryed it, it worked like a charm): Installing MPI in Linux.
For a list of available MPI routines check this out:
http://www-unix.mcs.anl.gov/mpi/www/www3/.
Fidgy is online!
Last year I’ve got a software engineering class and I had to work on a team project. The result was a small SIP client, we call it Fidgy. This semester I’ve got a class, IOM (that is Interactiunea om-masina, in Romanian, Human – Machine Interaction in English) and the Fidgy team was reunited (we’ve replaced a member, which was a goood thing). Our task is to create and maintain a site and a blog for publishing information about out homework and web technologies in general.
So here it is:
Now, the challenge is to find the best way so that the site could be easilly found by google seach for the keywords “interfete web” (that is web interfaces in english). I hope we’ll lear some SEO techniques and get some visible results soon.
ANTL – First Steps
I’ve done very good on my C# test (I scored 929 out of 1000), so I have now a MCTS 70-536 certificate.
Today I’ve started a little ANTLR tutorial. I need to get used to using ANTLR for one of my homeworks, for the compilers class. I use the following link:
http://javadude.com/articles/antlrtut/
I am still at the lexer part and I’ve encountered a problem. First, the tutorial uses ” for quotes and the ANTLR version I’m using (1.2.1) uses simple quotes. The problmes was related to the CHARLIT rule:
CHARLIT : '\''! . '\''! ;
Because I was writting a parser grammar, I couldn’t use ! to ignore simple quotes, so I constantly got the following error message:
(133): XL.g: illegal option output Consult the console for more information.
The console was empty, so no hints there… So in order to ignore simple quotes I’ve added a protected rule (for protected rules the lexer doesn’t create tokens):
protected QUOTE
: '\''
;
and I’ve added a filtering option:
options {
filter=QUOTE;
}
So now my chars literal rule looks like this:
CHARLIT
: QUOTE ~(QUOTE) QUOTE
;
Next step: string literals:)
Nervous
I haven’t written anything in a long time because I was preparring for a test: the MCTS 70-536. Finally, today, at 12:30PM… I’ll take the test. I am very nervous about it. I’ve studied a looot (I’ve read the book once then I’ve browsed it two times, I’ve done a lot of tests and questions), but still I am nervous. This is going to be my first real world test. I really hope I’ll do fine. Now I’m trying to answer some questions, but it is already the third time I’m doing this and… I’ve already learned the answers by heart:).
Anyway, the point is that I fill I’ve come a long way. I am much more confident in my C# programming abillities. I’ll have the chance to prove it today.