Swe3001 Os Da1
Swe3001 Os Da1
Swe3001 Os Da1
a) Shell Programming
• Handling the command line arguments
CODE:
echo Multiplication table of $1
c=`expr $1 - 1`
for (( i=1 ; i<=10 ; i++ ))
do
echo $1*$i = `expr $1 \* $i`
done
c=1
for(( i=1 ; i<=$1 ; i++ ))
do
c=`expr $c \* $i`
done
OUTPUT:
SHANMATHY SHREE AE 21MIS0498
• String reversal
CODE:
echo 22-12-2022 SHANMATHY SHREEE 21MIS0498
echo "enter a number :"
read n
sum1=0
sum=0
while [ $n -ne 0 ]
do
r=`expr $n % 10`
n=`expr $n / 10`
sum=`expr $sum \* 10`
sum=`expr $sum + $r`
done
echo the reversed number is $sum
OUTPUT:
SHANMATHY SHREE AE 21MIS0498
OUTPUT:
SHANMATHY SHREE AE 21MIS0498
OUTPUT:
SHANMATHY SHREE AE 21MIS0498
OUTPUT:
SHANMATHY SHREE AE 21MIS0498
CODE:
#include <unistd.h>
#include <sys/types.h>
#include <errno.h>
#include <stdio.h>
#include <sys/wait.h>
#include <stdlib.h>
int var_glb; /* A global variable*/
int main(void)
{
pid_t childPID;
int var_lcl = 0;
childPID = fork();
if(childPID >= 0) // fork was successful
{
if(childPID == 0) // child process
{
var_lcl++;
var_glb++;
printf("\n Child Process :: var_lcl = [%d], var_glb[%d]\n", var_lcl,
var_glb);
}
else //Parent process
{
var_lcl = 10;
var_glb = 20;
SHANMATHY SHREE AE 21MIS0498
OUTPUT:
SHANMATHY SHREE AE 21MIS0498
{
printf("main() is running...\n");
++i;
}
return 0;
}
OUTPUT:
SHANMATHY SHREE AE 21MIS0498
OUTPUT: