Hello friends, I have written a mini book on Cyber Security awareness for you, named "Hacking into Hackers' Head". This book uses common terms to explain things, and I'm sure you will get benefitted from it in your day to day life. It's available on Kindle and Google Play. Grab your copy now.

Tuesday, November 22, 2011

How to: Run and Compile C Programming in Ubuntu

Today I am going to show How to  Run and Compile C Programming in Ubuntu.

Just a few step and you will able to run this C in ubuntu...
so here we go ...

This is the source code of a very simple program which I am going to compile and run:
#include<stdio.h>
int main(){
int pid,ppid;
pid=getpid();


ppid=getppid();
printf("PID=%d\n,PPID=%d\n",pid,ppid);
}

To Compile:
First, save your C programs as file_name.c. Your file name can be any but the extension has to be .c. After that, open the terminal and type:


gcc<space>file_name.c<space>-o<space>file_name
I saved my file by process.c name
e.g.
gcc process.c -o process.c
If your program don’t have any errors, it will successfully compiled.
To Run:
After you successfully, compiled the program, you can see a file_name.out in the place where you save your program.
To run the program, type:

./file_name
e.g.
./process
OUTPUT: PID=1020
PPID=1052

No comments:

Post a Comment

We appreciate your valuable comments.

Scroll to Top