Professional Documents
Culture Documents
Perl_AWK_C
Perl_AWK_C
5DIP22IS09 28/03/2023
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:
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("Hello World... \n");
sleep(1);
}
return 0;
}
Output: