How to: Run and Compile C Programming in Ubuntu?

Posted on:
tags: , , , , ,
So guys my lab final exams are coming thats why I have to do practices of shell script and C programs in linux for Os lab Examination.
Here I will 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
If this post help you then pass the comment  
Admin
YTA




No comments:

Post a Comment

< >