0% found this document useful (0 votes)
49 views25 pages

Adobe Scan 28 Oct 2022

The document provides examples of commands in Linux/Unix like cat, date, man along with their usage and outputs. It also shows examples of C programs using functions and libraries along with Makefiles to automate building. Basic shell scripting programs are presented including one to calculate the average marks of students using awk.

Uploaded by

nayaniteja668
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views25 pages

Adobe Scan 28 Oct 2022

The document provides examples of commands in Linux/Unix like cat, date, man along with their usage and outputs. It also shows examples of C programs using functions and libraries along with Makefiles to automate building. Basic shell scripting programs are presented including one to calculate the average marks of students using awk.

Uploaded by

nayaniteja668
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Comman ds

Ustng Cat, date, ma)


Ustng
Cat Comman d
CTeate a frle

Cat7 frle.tat

Welcome to CYR Colleqe

)To vieuw a Stngle frle


cat file tat

Welcome to CVR College

17) To View muttple frles


4cat ftlet-tat Plea-tat
of fle to e)d of
w)
w) Cat CoMmand to append Coltents 0ne

another fPle
Cat -Faleltat 77ftlea.tat

to Contets 0f one frle to another


v)
) Cat
Cat Command Copy
le
-Hlel.txt 7 flea-tat
Cat

CVR COLLEG NGINEERING


Vastunagar, Mangalpalli(V) an (M), R.R. Dist. Ph -501 510
Page No. 2

Date Cofnand
Comnand to display Cument date ad time

date
LST

Output Sat 30 ApT 2023 OS:O5 : SS pm

DYsptay ttme 40 GiMT/UTC ime


Kone

$date -
UTC
Moo 06 Dec 2022 Ol:1822 p

date optto
$ date date o6|12|a0a2
Am 1ST
IST
2:00:00
Oudput: Sat l& Tun 2022

date date ayears ag0


Pm LST
Output F O6 DEC 2022 06S3:36

Man Command
man commAND NAMEJ
man prfott
9) man SECTIONNumJfCommAND NAME

man 2

CYP COLrc
Page No.

lbrartes

Butldng Statto and shared object

Statc 19brary
gedt ad doun.
10t addoum Ctnt a, 19t )

Tetu at

gedrt Suboum. G

90t Subnum (ot 3, 19t )

Tetuno -Y

gedrt uM.b

9+ addoum (90t , 19t 9)


Subpum (tot 3, t9t q

Matn fundto)

gedrt addsub-c
rndadecstdto.h 7

90-t mai0 ()
9nt a20,b-5
addnum (a, 6));
prvot+ (Ad detto0: l- d
1o",

("Subtractton -d\n') Subnun


(a,b))%
PiPott
etu) 0
CVR COLLEGE OF ENGINEERING
Vastunagar, Mangalpalli (V) ibranimpatan (M), R.R. Dist. Ph- 501 510
Page

Co mmands

C
c c Wall -O addnum.c
Subnum.

addnum. 0 Subnum.0 lles are qen enerated

a y ay CVOy myleb-a 0

lad4sub
Addrttoo: 25
Subtrattun: IS
Page No.

Shased brary
gedrt even.c
Votd even (nt a)
94 (a-a-= 0)

PTOt("Even gumben: "|.d, a)

gedt odd.
Votd add Cot a)

(ael.-0
prietf ("odd number 1-d) a)

gedt header h
Vord eNen(ot a)
Votd odd (ot
a)
qedt evenodd.c
+ndude stdro.h7
ftndudeheader.h
90t madOC)

P eotf (enter abn);


Scant ("4.4 4a)%

CVR COLLEGE OF
ENGINEERING
Vastunagar, Mangalpalli (V) lbrahimpatan (M), R.R. Dist. Ph - 501 510
Vastunagar, Mangalpalli (V) lbrahimpatan
(M), R.R. Dist. Ph - 501 ran
Page

even (a)
odda)
Tetumo 0

Commands odd.c
ewen.c

cc-klall -ewor tpto

cc -shared -o Ibcalu,so *0 y o u t

lall -0 yo
cc-K/home/ewr
cvz/shared lebrary|-

eNenodd.C-lcalau
-Tpath
e
Ihome |Cv7
-Wl,
Itbrany |
A Ihomefcvr [shared
7 ewenodd-c
-lcalcu

SharedIrbrary |-Nall -o myoutl

myouti
Output
Enter a

S
odd umber:5
P a g eN o .

utilPty
Sample proje ct busldng wtth Make

Tead 10put.C
#Hodude <stdto.h7
Hocdude <unistd-hz
ndude header.b
Vot d Sead Cnt a)
user 1s d 1)
from
PrYotf ( T6e value of 2

PrYtt ( I am Tead 9nput "

Khtte-0utput. c

dFrodade <stdto.hz
rodude header.h
vofd belloc)

Prfotf (I am t Otte-oudput")

ProceSs-C

rodude <stdro.h7
rodude 'header.h
Vo9d process ()
Priotf ( t am 10 process \n")

CVR COLLEGE OF
ENGINEERING
Vastunagar, Mangalpalli (V) Ibrahimpatan
(M), R.R. Dist n
Page

Maln. C
odu de rstd ?o.b7
PO dude beader.h
9t afC)

99t a
PT?otf ( Enter any numb er:")
ScanfC-1d, a )
read (a)5
bell o C)
Process C)5
retuo O

header.b
Vor d belloc)
Vord Tead C10t

Vord ProcessC)

mahefle maf0- o b ead er.b


put. o nwTteOdput. o Process .o
Pro cess : r e a d -10 main. O
o Ytte-Output
0
pro cess Ob
gcc Tead-1oput.
header b - O
procesS

ecbo make Complete

CVR COLLEGE OF ENGINEERING


Mangalpalli (V) Tbrahimpatan (M), R.R. Dist. Ph 501 510
-

Vastunagar,
Page No

Tead 90 put .0
9cc-C 1ead-input.
1te-Output.0
gcc-c klrtte_ output.
Process.0:
gCc - ProcesS.
Maf0.0
4CC-C Main.
dean
.0 PTOCes s

eh o
frles are Temoved
ake

process
Output
ter any Oumber lo
he value of a from usen 15 10

I am 40
Tead put
T an tO
procesS
Iam 90 kotte Output

CVR COLLEGE OF
Vastunagar, Mangalpalli (V)
vastunagar, Mangalpalli (
ENGINEERING
lbrahimpatan (M), R.R. Dist.
l Ph
PageN

SCripts
and Ank sample
tTWK Command

avq-Monks.aw b
BEGIN

Fs "H
Count-0
total- 0 student
morks of each
prttt("Avq

Det

1<NPS 1r+)
fol 1-a;
-total-manks + fi
total- marks

aNg total_ marks /NF

prmtf($
totale total + total-manks
Count- ountt

END

dass axq-total/Count

Prtotf ("dass_avq , dass- avq )

CVRCOLLEGE OF ENGINEERING
Vastunagar, Mangalpali (V)
lbranimpatan (M), R.R. Dist. Ph -501 510
PageNo.1

Marks-tt
1201 lo 20 30 4-0 SO

120 2 20 40 so 60 0

1203 20 3o 60

1204 SO 60

Ouctput
awk avq-marhs awb maksrta

Avq
tVg marks of each stud ent
1201 16-6667
1202 42.65
1203 82-S

12-04 96
Cass-awg 30a.s

CVR COurc.
Page NO

numbers uPng
usPn
Baste shell Sortpting Proqrams numbers

two
to
add
APOua shell Scspt proqa
Command lene aquments
H bro 1basb
Iene-add.sh

Command-
name
PToqram num
bers
be

to add
#shell Sorrpt proqram
Sum apr t 42
sum
ech o sum ts

outpud
1520
$sh Comm and-Ieoed- add-sh
Sum PS:35
numbers
tuwo
program
to Swap
Soript
A n u a shel

# / beolbash
proqran name Swap.sh
two numberS
to Shwap
#shell Srtpt progqram
Ouum)=l
Duma-20

ccho Before Swappinq

echo Numl Dum


Numa:fOuma
echo
Oum3 numi

CVR COLLEGE OF ENGINEERING


Vastunagar, Mangalpalli (V) loranimpatan (M), R.R. Dist. Ph -

501 510
PageNo.

Oum- num2
Duma- num3
echo After Swapprng
echo Numi num
echo Num2: num

Output
sh Swap.sh
Befose Swappng
Nunl: 0
Num2 20

Aftr Snapprng
Num: 90
Numa : 10
întegers nd
to Tead two
POua shell Sortptt proqam
Preot the Subtractton

#/bo/bash
pTogam name Reader.Sh

program to ead a1teqers and prit thur


9nua shell sompt
lnua
# Subbratfon

ech o Enter ) uml

Tead num
CVR COLLEGE OF ENGINEERING
Vastunagar, Mangalpalli (V) brahimpatan (M), R.R. Dist. Ph - 501 510
Pa

echo Enter ouna


Tead numa
Tesut a EapT numl-fnum a

eho Substodtto s 4result


Oudput
sh Reader.sh
Enter Quml
20
Eter Quma

Sub bratfon fs 10

CVR COLLEGE OF
Vastunagar, Mangalpalli (V) IhrahimnaENGINEERING
Page No.

tall,
Shl frtters Cut, qrep,head,
ptn9 ustng
)Cut. sh
# /brofbash
Cuct note t a t
-b 1,3,3.4t
echo
Cat 7 Dotetat

Hello
oel Come to

CNR Colleqe
Outpur
bash Cut.sh
Hllo
Nlc
CNR

9Tep.sh
#1/beo/bash

rep T 9Tep.tt

echo
9nep ft rep.tat

echo

Cat 7 9Tep.tut

Tbts 15 CNT dlege


We ane rom t depantment
Output
basb qep. Sh
:Tbrs s T Colleq

e ase from t dparm ent

head.
#+1/bvo/hash
echoHead rs
bead-3 netetzt

echo
Output
ttead s
telo
hued Cone to

CVR Clle
turl.sh

AL /ben /bash
ccho 7Tall 15:
ootertat
tasl

eho
output
Tall s
Nellome to

CNR Cll eqe


ENGINEERING
CVR COLLEGE OF
lbrahimpatan (M), R.R. Dist. Ph 501 510
-

Vastunagar, Mangalpalli (V)


/ .n. DISt. Ph - 501 6
4/bvn/bauh
herfe abo.tat
echo
Cat 7 ahc t a t

output
bash abc.sh

N
mor C-(90-1.)
Page System C al
C a l1ls
s

System

ustng

plemeat Commands
i9 C the followin g Untn
aCat b) Cp cwc
a Ca Command uctng Systen all

todude <stdro.h7
10dude sys/types h
rndude <sysl stat.h7
t fndude <funtl .h7
indude <untstd.h7
7Dt mato (10tt argc char targ vl3J) i
10t fd1,
chor bufla]
td- opeo (argvli], 0-RDONLy,0777)
t (td- -angc)?

pTPOtf(frle open emo

else
ohrle (C1e Tead (td. buf. )) 7o)}
prtotf (/c', butlo])
dose(td)
etun 0j

Outpu qCC- Catsys Calsys.C


-leat sys aa Hello
Hello NoTHd herld
CVR COLLEGE OF ENGINEERING
Vastunagar, Mangalpalli (V) lbrahimpatan (M), R.R. Dist. Ph -501 510
P a gN
eN O .

Gommand us90g Ssten


indude <stdro.hz
4odude <ustst d.b7
n dude <fetl.h 7
#1ndude <std|:b.h 7
1
t mado (0t argC, chav anqv 1
90t fdu fda,0%
t-0pen (arqvli1,o-RDONLY)
chay buffer 8o]
14 Gtde -){
Pemor (open')
CAt 0)
J0CREAT, 0666)
O_WRONLY
Td2- 0pen (anqv/a,
(Tead Cfd, tbutfer. 0) i
ohsl e

OTtte Cfda, tbutfen, 1)

doseCF4)
doseLfda)s
Teus 0

o utput gcc Copy Copy.c Cout yo


Cat 7 a a
Hllo
tello
world

Copy aa yoy
CVR COLLEGE OF
ENGINEERING
Vastunagar, Mangal pali (V) lbranimpatan (M), R.R. Dist. Ph -501
510
Page

8
Commang
cto 9mplement ls -L frlename
todude <stdi o.h7
todude <drrent.b7
9odude <stri0g.b7
10cude <emoo.h
ndude <std]tb.h7
90t mao (nt ar 9e, thay t
angvl )1
DIR dr
Struet drent * sd

dh- opendm(". ")%


f Cdme = NULY
unable to ope dredo
poot C'eror
entt)

Teaddr (drr)) !=NULL)


ohrle ((sd -

prtntf("z7-|s\n Sd-> d-n ame)

dosederCdrr)
Tehuno 0

Ouwtpu gcc-olssys ssys. C

10sys
77my 77M0
77 tent t t lssys
77 Out 77 myoudput

CVR COLLEGE OF ENGINEERING


Vastunagar, Mangalpalli (V) ibrahimpatan (M), R.R. Dist.
Ph-501 510
Page No.

cess

te a C
program to a) reate Zombre
b)To avord Zombte state ef a proceSS

Geate Zombte Process


#todude <stdro.h7
ndude <stdlsb.h 7
ndude <untstd.b7
t Main (1nt arqe, chart arq| 7)
uhcfgn ed 9ot prd
Int Tet, 1

Pr-getprdd)
Pritot-+Cmy process Pd 15 dlo' prd)
PTtottC About to Create chrld process|n
sete fovk )

+Cetco1{
pemorfork)

9F(Tel -c0)1

preot+'I am chrl4 process, myprd- ol-4\n'", qtprd)


sutume me: J.4 \o", Tect)
Pxtotf ( I am chrld fok
fonre0 <ST9+t)1
Sleep (0
PrYnt+(chrld r:4.d\o,1)
enft (EIT SUCCESS)

CVR COLLEGE OF
ENGINEERING
Vastunagar, Mangalpali (V) lbrahimpatan (M), R.R. Dist. Ph -501 510
Page N0.

se t(red ro)i
In, qdprd)
PrPOHC I am parant Process. Myprde 1-d
rdumed me: -1d nTa)
am parent fonk
fo (-0j<1ogj+7)
sleept0%
printtC porent J:-/d 3)
Catt (EAT -SUCCESs)

PvtotfCommoo Code);
e t (ENT SUCCESs)

Oudtput My proces 9 s a436


About to CTeate chtld process
am Parent pocess, myp?d eat3
am parent ttrk yetumed me a437
Tau) chrld piocess, Myp?de Q437
Tan dhrld foh 1tunned me
Paret:o
cheld 1:o Paend f:S
Panet I Parent 6
cheld 1I Paxet J 7
Parent 1 Parent 1 9
chrld 1: Parent:9
chrld f33
Poyat :3
chrld Y:4
Pan ent J4

CVR COLLEGE OF
Vastunagar, Mangalpalli (V) ENGINEERING
lbrahimpatan (M
b) To
avotd Zombse 6tate o Pro Cesss

#o dude <std?o.h7
9odude <stdltb.b7
todude cun1std-h7
ndude <sys) oatt.h
T0t Mato (rot arge, char tarqv 1)
staned 9ot prd
totset,1,f
Prd- get prd 0)%

Ptntf my Process 1d 1s/u\n',prdl


Process\o')
chald
Pitatf About to at e

Tt etorkt0%

pem or forlh )%

PF(set- =0)?
0
process, myprdo
-fpdio", gdpid
Pvotf( am thild
me t |d \o'set)
am chrld ferk Tehunned
PTrhtt (I
3
fen (f-03 1< St1+t)
9)3
Pt9t+ (hrld 1:-1d lo"
Caft (EXIT SUCCESs)

dse 1(het ro)


40t Status

CVR COLLEGE OF ENGINEERING


Vastunagar, Mangalpalli (V) lbrahimpatan (M), R.R. Dist. Ph -

501 510
Page VU.

qdpfd))
PTot-+(I am Process, myprde d.d\o,
Panent rd)
Ta

PTPot+ (L /.4\0
Daxent foh Tetung ed
me:
am

wat (4 status)
T (WIFEXITED(Stadu s))3
PrPot+ (hild prd---4tepoated', Tet) xITS T A T U S( s t a t u s ) )

prPhtf Cchrlds eart Stadus 1s


din

fo Cj-07 j<s]+t)}
Protf (ponent J - d\n'. f)%

enut [ExlT SUCCESS)

PTYntf (Comman Code'


enrt (ExIT SUCCESS)

Oupu
57)
W PrbCeSS 1d 9

About to Create Chrld process

a o Ppament procesS, myptd. 257|


a m ponent ferh reumed me 2573

T am chtl4 ProoeSS, myp?d2513


Tam chld toh tume meo

chsld 10

CVR COLLEGE OF
Vastunag1 lli (00 ENGINEERING
dald t:
chrld 1:3
Cheld 3 Status ts 0

sttus
chyl4 14 chrlds
chrlds
erl

a579
temmated
Chrld prd-
Paxent J: 0

PanentJ1

Panent J:?
Ponent 1:3

Panent J

You might also like