Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Ranjan Shettigar

5DIP22IS09 28/03/2023

10.Implement a perl script that Repeat given string

Code:

#!/usr/bin/perl
print "enter the string:" ;
$a=<STDIN>;
print "number of times string to be displayed:" ;
chop($b=<STDIN>);
$c=$a x $b;
print "result is:\n$c";

Output:
11.Implement a perl script that takes file as an argument, checks whether file exists
and prints binary if file is binary.

Code:

print("Enter the filename: ");


$filename=<STDIN>;
chop ($filename);
if(-e $filename)
{
print("File $filename exists.\n");
if(-B $filename)
{
print("binary file\n");
}
else
{
print("Not a binary file.\n");
}
}
else
{
print("File $filename does not exist.\n");
}

Output:
12.Design an Awk program to provide extra symbol( i.e., * or @ ) at the end of the
line(if required) so that the line length is maintained as 127.

Code:
{
y= 127-length($0)
printf "%s", $0
if (y > 0)
for(i=0;i<y; i++)
printf "%s","*"
printf "\n"
}

Output:

13.Implement a perl script that takes file as an argument, checks whether file exists
and prints binary if file is binary.

Code:

{
if(length($0) <= 15)
print $0
else
{
x=$0
while(length(x) > 15)
{
printf "%s\n", substr(x,1,15);
x=substr(x,16,length(x)-15);
}
printf "%s\n",x
}
}
Output:]

14.Write a C program that creates a child process to read commands from the
standard input and execute them.

Code:

#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<string.h>

int main()
{
int pid,status;
char comd[20]; pid=fork();
if (pid==0)
{
printf("Child Process\n");
while(strcmp(comd, "exit") !=0)
{
printf("[user@localhost-]$ ");
gets(comd);
system(comd);
}
exit(0);
}
else
{

wait(&status);
printf("Parent Process\n");
}
}
Output:

15.C Program to register signal handler for SIGINT and when it receives the signal,
the program should print some information about the origin of the signal.

Code:
#include<stdio.h>
#include<signal.h>
void sig_handler(int signo)
{

printf("Signal caught is : %d ", signo);


}
int main(void)
{
(void) signal (SIGINT, sig_handler); // pre-defined
while(1)

{
printf("Hello World... \n");

sleep(1);
}
return 0;
}

Output:

You might also like