Showing posts with label part. Show all posts
Showing posts with label part. Show all posts
Thursday, February 23, 2017
Structure Part I The Basics
Structure Part I The Basics
Today we are going to go through Structures from defining structures to using structures.
Structures are just a collection of different types under one roof (you can even put one type only!). So that means they give you flexibility of grouping different data types (like int, char, or even char[]) under one name.
So let us start with obviously defining a Structure. In `C` we declare a structure as simply as this:-
struct dob {
int day;
int month;
int year;};
1: In the above code segment struct is a keyword which defines structure.
2: Followed by struct keyword (dob) is the name of our structure.
3: Elements of struct are defined inside braces {} as we did (int day; etc).
4: After ending brace we place a terminator ; to end the declaration.
So now you know how to define a structure but how to create its instances now?
To create a variable of our structure we just need to do this:
struct dob date;
This now declares date as a structure variable of type dob.
1: Here struct dob is our above declared structure.
2: date is a variable of type dob.
So ok we have a structure and a variable of that type but how can i access its parts?
well we can access it and assign it so simply like this:-
date.day = 19;date.month = 10;date.year = 1990;
Note here we use the dot (.) operator to access the fields (parts) of our structure.
ok everything looks nice so for but how in the world can i read data into this structure variable? Again no worries its again simple:-
scanf(%d, &date.day);scanf(%d, &date.month);
that was pretty easy but I was wondering how can i print its data?
Just do it like this:-
printf(Day: %d, date.day);printf(Month: %d,date.month);printf(Year: %d, date.year);
Again remember we use dot (.) operator to access members of a structure.
So we now know how to define and declare a structure, how to access its members, how to read data in it, and how to print data of a structure. Oh that was a tough job..!
Now let us put it together in a single C Program.
/***********************************************/Output:
#include <stdio.h>
struct dob {
int day;
int month;
int year;
};
int main(void) {
struct dob date;
date.day = 19;
date.month = 10;
date.year = 1990;
printf(Day is : %d, Month is: %d, and Year is %d ,
date.day,date.month, date.year);
printf(Enter Day, Month, and Year separated by spaces: );
scanf(%d %d %d, &date.day,&date.month,&date.year);
printf(Your entered Date is: %d/%d/%d,
date.day,date.month,date.year);
return 0;
}
Day is : 19, Month is: 10, and Year is 1990
Enter Day, Month, and Year separated by spaces: 1 1 2014
Your entered Date is: 1/1/2014
Available link for download
Monday, February 20, 2017
Linux Command Line Hackery Series Part 5
Linux Command Line Hackery Series Part 5

Welcome back to the Linux Command Line Hackery series, this is Part-V of the series. Today we are going to learn how to monitor and control processes on our Linux box, so wrap your sleeves up and lets get started.
Command: ps
Syntax: ps [options]
Description: ps displays information about the currently running processes. Some of the common flags of ps are described briefly below
Flags:
-A or -e -> select all processes
-a -> select all processes except both session leaders and processes not associated with a terminal.
T -> select all processes associated with current terminal
-u <username or id> -> select all processes of a given user or userlist
Open up a terminal and type ps:
ps
what youll see is a list of processes currently running in your terminal. One important thing to notice in the output is whats called as PID which stands for process ID. It is the number that uniquely identifies a process. Just keep that PID concept in mind well use it soon.
OK I know thats not really what you want to see rather you want to see all the processes that are currently running on your box. Dont worry we have flags to rescue, in order to see all the processes you can use the -e flag like this:
ps -e
Boom! you get a long list of processes currently running on your machine (dont stare at me like that, you asked and I gave you that). If you want to see processes of a particular user you can type the following command in your terminal:
ps -u bob
here "bob" is a username. This command will list all processes of the user with effective user name of bob.
You can do a full-format listing of the processes using the -f flag like this:
ps -fu bob
But the output of the ps command is a snapshot not really a live preview of what is going on in your box. I know your next question is going to be something like this, Isnt there a command in Linux that gives me a live updating information of the processes? Yes, there is a command called top that well learn about next.
Command: top
Syntax: top [options]
Description: top gives a dynamic real-time view of a running system. That is, it gives the up-to-date information about all the processes running on your Linux box (sounds fun!). Besides giving information about current processes and threads top also provides a brief system summary.
To start top just type this command:
top
and youll get a nice and cute looking ugly display :). Well what the heck is going on here you might ask, right? What you get is information about what is going on with your computer. To see what more can you do with top just type <h> within the program window and youll be given list of options that you can play with.
OK looking at what processes are going on in your box is cool but what if you want to terminate (or close) a process, is there a command line utility for that? Yes, there is and thats what we are going to look at next.
Command: kill
Syntax: kill [options] <pid> [...]
Description: kill is used to send a signal to process which by default is a TERM signal meaning kill by default sends a signal of termination to process (Cruel guy). To list the available signals we can use the -l or -L flag of the kill command.
To simply terminate a process we provide kill command a PID (process ID) and it will send the TERM signal to the process. So to kill a process first well list the running processes and then well keep the PID of the process in mind that we want to terminate. After that well issue the kill command with the PID that we just found.
ps -ax
kill 1153
the above command will send a TERM signal to the process whose PID is 1153, as simple as that.
We can also use our already learned skills to refine the output of ps command. Say we have a xterm terminal running on our box and we want to terminate it. By using ps command all alone well get a long listing of all processes running on our box. But we can limit the output of ps command to just those processes that were interested in by piping ps command with the grep command like this:
ps -ax | grep xterm
wow! thats amazing, were able to pull out only those results from the ps command that contained xterm in them. Isnt that a cool trick? But what is that vertical bar ( | ) doing in the middle, you may be thinking, right? Remember we learned about the input and output re-directors previously, the vertical bar (pipe in geeky terms) is another re-director whose task is to redirect the output of one command as input to another command. Here the pipe redirects the output of ps -ax command as input to grep command and of-course from the previous article you know that grep is used to search for a PATTERN in the given input. That means the above command searches for the xterm word in the output of ps -ax command and then displays just those lines of ps -ax command which contain xterm. Now get that PID and kill that process.
Thats it for today, try these commands up on your own box and remember practice is gonna make you master the Linux command line. :)
Available link for download
Wednesday, January 25, 2017
BACKUP WINDOWS WITHOUT THIRD PARTY SOFTWARE PART III
BACKUP WINDOWS WITHOUT THIRD PARTY SOFTWARE PART III
Now I will introduce you to backup and restore your windows 8 or 8.1. The way to restore windows 8 or 8.1 is same windows 7 that I posted "BACKUP WINDOWS WITHOUT THIRD-PARTY SOFTWARE PART II".
BACKUP:
Step 1: Access to Control Panel:

Step 2:

Step 3:

Step 4:

Step 5: You can select save your image backup on Local partition or an other partition on your LAN network.

Step 6:

Step 7:

Step 8: Wait until it done and result like below:

RECOVERY:
You do samely Step 1 to Step 4 but now you select Recovery instead of System image backup:

Step 2: Now you download System image recovery disc for windows 8 or 8.1 from here and do like with windows 7 to restore. You can read my post here.
Good luck!
Linkstoos!
Available link for download
Subscribe to:
Posts (Atom)