0% found this document useful (0 votes)
5 views26 pages

USP Manual - NoRestriction

Uploaded by

manjulam.csi
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)
5 views26 pages

USP Manual - NoRestriction

Uploaded by

manjulam.csi
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/ 26

Sri Adichunchanagiri Shikshana Trust ®

SJB INSTITUTE OF TECHNOLOGY


BGS Health & Education City, Kengeri, Bangalore-60.

DEPARTMENT OF
COMPUTER SCIENCE AND ENGINEERING

A
MANUAL FOR

VI SEMESTER
UNIX SYSTEM PROGRAMMING
&
COMPILER DESIGN
LAB MANUAL
Subject Code: 10CSL68

By:
Darshan K.R
Lecturer, Dept.of CS&E
Unix Systems Programming and Compiler Design Manual

Syllabus
List of Experiments for USP: Design, develop, and execute the following programs

1. Write a C/C++ POSIX compliant program to check the following limits:


(i) No. of clock ticks (ii) Max. no. of child processes (iii) Max. path length
(iv) Max. no. of characters in a file name (v) Max. no. of open files/ process

2. Write a C/C++ POSIX compliant program that prints the POSIX defined configuration options supported
on any given system using feature test macros.

3. Consider the last 100 bytes as a region. Write a C/C++ program to check whether the region is locked or
not. If the region is locked, print pid of the process which has locked. If the region is not locked, lock the
region with an exclusive lock, read the last 50 bytes and unlock the region.

4. Write a C/C++ program which demonstrates interprocess communication between a reader process and a
writer process. Use mkfifo, open, read, write and close APIs in your program.

5. a) Write a C/C++ program that outputs the contents of its Environment list
b) Write a C / C++ program to emulate the unix ln command

6. Write a C/C++ program to illustrate the race condition.

7. Write a C/C++ program that creates a zombie and then calls system to execute the ps command to verify
that the process is zombie.

8. Write a C/C++ program to avoid zombie process by forking twice.

9. Write a C/C++ program to implement the system function.

10. Write a C/C++ program to set up a real-time clock interval timer using the alarm API.

List of Experiments for Compiler Design:

11. Write a C program to implement the syntax-directed definition of “if E then S1” and “if E then S1 else S2”.
(Refer Fig. 8.23 in the text book prescribed for 06CS62 Compiler Design, Alfred V Aho, Ravi Sethi, and
Jeffrey D Ullman: Compilers- Principles, Techniques and Tools, Addison-Wesley, 2007).

12. Write a yacc program that accepts a regular expression as input and produce its parse tree as output.

Note: In the examination each student picks one question from the lot of all 12 questions.

Prepared By: Darshan.K.R, Dept.of CS&E, SJBIT Page 2


Unix Systems Programming and Compiler Design Manual

1. Write a C/C++ POSIX compliant program to check the following limits:


(i) No. of clock ticks (ii) Max. no. of child processes (iii) Max. path length
(iv) Max. no. of characters in a file name (v) Max. no. of open files/ process

To Open the Editor with filename


[root@localhost /]# gedit limit.cpp

#define _POSIX_SOURCE
#define _POSIX_C_SOURCE 199309L
#include<iostream.h>
#include<unistd.h>
int main()
{
int res;
if((res=sysconf(_SC_CLK_TCK))==-1)
cout<<"System doesnot support\n";
else
cout<<"Number of Clock Tick:"<<res<<endl;

if((res=sysconf(_SC_CHILD_MAX))==-1)
cout<<"System doesnot support\n";
else
cout<<"Maximum Number of Child Process that process can
create:"<<res<<endl;

if((res=pathconf(“/”,_PC_PATH_MAX))==-1)
cout<<"System doesnot support\n";
else
cout<<"Maximum Path Length:"<<res<<endl;

if((res=pathconf(“/”,_PC_NAME_MAX))==-1)
cout<<"System doesnot support\n";
else
cout<<"Maximum No.of Character in a
filename:"<<res<<endl;

if((res=sysconf(_SC_OPEN_MAX))==-1)
cout<<"System doesnot support\n";
else
cout<<"Maximum Number of opened files per
process:"<<res<<endl;

return 0;
}
Prepared By: Darshan.K.R, Dept.of CS&E, SJBIT Page 3
Unix Systems Programming and Compiler Design Manual

To Run the Program

[root@localhost /]# g++ limit.cpp


[root@localhost /]# ./a.out

OUTPUT

Number of Clock Tick:100


Maximum Number of Child Process that process can create:999
Maximum Path Length:4096
Maximum No.of Character in a filename:255
Maximum Number of opened files per process:1024

Prepared By: Darshan.K.R, Dept.of CS&E, SJBIT Page 4


Unix Systems Programming and Compiler Design Manual

2. Write a C/C++ POSIX compliant program that prints the POSIX defined configuration
options supported on any given system using feature test macros.

To Open the Editor with filename


[root@localhost /]# gedit testmacro.cpp

#define _POSIX_SOURCE
#define _POSIX_C_SOURCE 199309L
#include<iostream.h>
#include<unistd.h>
int main()
{
#ifdef _POSIX_JOB_CONTROL
cout<<"System Supports Job Control feature"<<endl;
#else
cout<<"System doesnot support job control\n";
#endif

#ifdef _POSIX_SAVED_IDS
cout<<"System Supports saved set-UID and saved set-GID"<<endl;
#else
cout<<"System doesnot support saved set-UID\n";
#endif

#ifdef _POSIX_CHOWN_RESTRICTED
cout<<"System Supports Change Ownership feature:"<<endl;
#else
cout<<"System doesnot support change Ownership feature\n";
#endif

#ifdef _POSIX_NO_TRUNC
cout<<"System Supports Path truncation option:"<<endl;
#else
cout<<"System doesnot support Path truncation \n";
#endif

#ifdef _POSIX_VDISABLE
cout<<"System Supports Disable Character for files:"<<endl;
#else
cout<<"System doesnot support Disable Characters \n";
#endif

return 0;

Prepared By: Darshan.K.R, Dept.of CS&E, SJBIT Page 5


Unix Systems Programming and Compiler Design Manual

To Run the Program

[root@localhost /]# g++ testmacro.cpp


[root@localhost /]# ./a.out

OUTPUT

System Supports Job Control feature


System Supports saved set-UID and saved set-GID
System Supports Change Ownership feature
System Supports Path truncation option
System Supports Disable Character for files

Prepared By: Darshan.K.R, Dept.of CS&E, SJBIT Page 6


Unix Systems Programming and Compiler Design Manual

3. Consider the last 100 bytes as a region. Write a C/C++ program to check whether the
region is locked or not. If the region is locked, print pid of the process which has locked. If
the region is not locked, lock the region with an exclusive lock, read the last 50 bytes and
unlock the region.

[root@localhost /]# gedit lock.c

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
struct flock fl = {F_WRLCK, SEEK_SET,0, 100,0 };
int fd;
char buf[50];
fl.l_pid = getpid();
if ((fd = open(argv[1], O_RDWR)) == -1)
{
perror("Can't open file");
exit(1);
}
if (fcntl(fd, F_SETLK, &fl) == -1)
{
perror("Can't set Exculsive Lock");
exit(1);
}

else if(fl.l_type!=F_UNLCK)
{
printf("File Region has been Exclusively Locked by
process:%d\n",fl.l_pid);
}
else
{
printf("File is not Locked\n");
}

printf("Press ENTER to Release lock:\n");


getchar();
fl.l_type = F_UNLCK;
printf("File has been Unlocked\n");
lseek(fd,50,SEEK_CUR);
read(fd,buf,50);
printf("Last 50 Byte Content in the file is\n");
printf("====================================\n");
printf("%s\n",buf);
return 0;
}

Prepared By: Darshan.K.R, Dept.of CS&E, SJBIT Page 7


Unix Systems Programming and Compiler Design Manual

To Run Program

Create a file, here we are creating a file with name demo with the
following Content:

Consider the last 100 bytes as a region. Write a C/C++ program to


check whether the region is locked.

[root@localhost /]# cc lock.c


[root@localhost /]# ./a.out demo

OUTPUT

File Region has been Exclusively Locked by process: 4087


Press Any Key to release lock:

File has been Unlocked


Last 50 Byte Content in the file is
====================================
/C++ program to check whether the region is locked

Prepared By: Darshan.K.R, Dept.of CS&E, SJBIT Page 8


Unix Systems Programming and Compiler Design Manual

4. Write a C/C++ program which demonstrates interprocess communication between a


reader process and a writer process. Use mkfifo, open, read, write and close APIs in your
program.

[root@localhost /]# gedit writer.c

Writer Process (writer.c)

#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

int main()
{
int fd;
char * myfifo = "/tmp/myfifo"; /* create the FIFO (named pipe) */
mkfifo(myfifo, 0666);

fd = open(myfifo, O_WRONLY);
write(fd,"Hi", sizeof("Hi")); /* write "Hi" to the FIFO */
close(fd);

unlink(myfifo); /* remove the FIFO */


return 0;
}
[root@localhost /]# gedit reader.c

Reader Process (reader.c)


#include <sys/stat.h>
#include <unistd.h>

#define MAX_BUF 1024


int main()
{
int fd;
char *myfifo = "/tmp/myfifo";
char buf[MAX_BUF];

/* open, read, and display the message from the FIFO */


fd = open(myfifo, O_RDONLY);
read(fd, buf, MAX_BUF);
printf("Received: %s\n", buf);
close(fd);

return 0;
}
Prepared By: Darshan.K.R, Dept.of CS&E, SJBIT Page 9
Unix Systems Programming and Compiler Design Manual

To Run the Program

[root@localhost /]# cc writer.c


[root@localhost /]# ./a.out

After this Open New Terminal by pressing shift+ctrl+N or Go to File-


>Open Terminal

[root@localhost /]# cc reader.c


[root@localhost /]# ./a.out

OUTPUT
Received: Hi

Prepared By: Darshan.K.R, Dept.of CS&E, SJBIT Page 10


Unix Systems Programming and Compiler Design Manual

5a) Write a C/C++ program that outputs the contents of its Environment list

[root@localhost /]# gedit env.c

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

int main()
{
int i;
char **ptr;
extern char **environ;
printf("List of Environmental Variable\n");
printf("--------------------------------\n");
for (ptr = environ; *ptr != 0; ptr++)
printf("%s\n", *ptr);

exit(0);
}

To Run the Program

[root@localhost /]# cc env.c


[root@localhost /]# ./a.out

OUTPUT
List of Environmental Variable
--------------------------------

SSH_AGENT_PID=3008
HOSTNAME=localhost.localdomain
DESKTOP_STARTUP_ID=
SHELL=/bin/bash
TERM=xterm
HISTSIZE=1000
KDE_NO_IPV6=1
GTK_RC_FILES=/etc/gtk/gtkrc:/root/.gtkrc-1.2-gnome2
WINDOWID=50331729
QTDIR=/usr/lib/qt-3.3
QTINC=/usr/lib/qt-3.3/include
USER=root
HOME=/root
SHLVL=2
GNOME_DESKTOP_SESSION_ID=Default
LOGNAME=root
QTLIB=/usr/lib/qt-3.3/lib
CVS_RSH=ssh

Prepared By: Darshan.K.R, Dept.of CS&E, SJBIT Page 11


Unix Systems Programming and Compiler Design Manual

5b. Write a C / C++ program to emulate the unix ln command


[root@localhost /]# gedit ln.cpp

#include<iostream.h>
#include<unistd.h>
int main(int argc,char* argv[])
{

if(argc!=3)
{
cout<<"Usage ./a.out sourcefile destination file\n";
return 0;
}

if(link(argv[1],argv[2])==-1)
{
cout<<"Can't Link\n";
return 1;
}
else
{
cout<<"Files have been Linked\n";
}
return 0;
}

To Run the Program

[root@localhost /]# g++ ln.cpp


[root@localhost /]# ./a.out ln.cpp newfilename

OUTPUT

Files have been Linked


[root@localhost /]# gedit newfilename (The Content of Source file
Will be Copied to newfilename)

Prepared By: Darshan.K.R, Dept.of CS&E, SJBIT Page 12


Unix Systems Programming and Compiler Design Manual

6. Write a C/C++ program to illustrate the race condition.

[root@localhost /]# gedit race.c

#include<stdio.h>
#include<stdlib.h>
#include<error.h>

static void charatatime(char *);

int main(void)
{
pid_t pid;

if ((pid = fork()) < 0)


{
printf("fork error");
}
else if (pid == 0)
{
charatatime("output from child\n");
} else
{
charatatime("output from parent\n");
}
exit(0);
}

static void charatatime(char *str)


{
char *ptr;
int c;

setbuf(stdout, NULL); /* set unbuffered */


for (ptr = str; (c = *ptr++) != 0; )
putc(c, stdout);
}
To Run the Program

[root@localhost /]# cc race.c


[root@localhost /]# ./a.out

OUTPUT

output from child


output from parent
[root@localhost /]# ./a.out
output from cohuitlpdu
t from parent
[root@localhost /]# ./a.out
oouuttppuutt ffrroomm pcahrieldnt

Prepared By: Darshan.K.R, Dept.of CS&E, SJBIT Page 13


Unix Systems Programming and Compiler Design Manual

7. Write a C/C++ program that creates a zombie and then calls system to execute the ps
command to verify that the process is zombie.

[root@localhost /]# gedit zombie.c

#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

int main ()
{
pid_t child_pid; /* Create a child process. */
child_pid = fork ();
if (child_pid == 0)
{
exit (0); /* This is the child process.Exit immediately. */
}
else
{
sleep(3); /* This is the parent process. Sleep for a minute. */
system("ps -e -o pid,ppid,stat,cmd");
}
return 0;
}

To Run the Program

[root@localhost /]# cc zombie.c


[root@localhost /]# ./a.out

OUTPUT

PID PPID STAT CMD


1 0 Ss init [5]
2 1 S [migration/0]
3 1 SN [ksoftirqd/0]
4 1 S [watchdog/0]
5 1 S [migration/1]
6 1 SN [ksoftirqd/1]
7 1 S [watchdog/1]
8 1 S [migration/2]
9 1 SN [ksoftirqd/2]
10 1 S [watchdog/2]
3087 3084 S gnome-pty-helper
3088 3084 Ss bash
3166 3088 S+ ./a.out
3167 3166 Z+ [a.out] <defunct> //Zombie Process
3168 3166 R+ ps -e -o pid,ppid,stat,cmd

Prepared By: Darshan.K.R, Dept.of CS&E, SJBIT Page 14


Unix Systems Programming and Compiler Design Manual

8. Write a C/C++ program to avoid zombie process by forking twice.

[root@localhost /]# gedit avoidzombie.c

#include<stdio.h>
#include <sys/wait.h>
#include<errno.h>
#include<stdlib.h>

int main()
{
pid_t pid;

if ((pid = fork()) < 0)


{
printf("fork error");
}
else if (pid == 0)
{ /* first child */
if ((pid = fork()) < 0)
printf("fork error");
else if (pid > 0)
exit(0);
sleep(2);
printf("second child, parent pid = %d\n", getppid());
exit(0);
}

if (waitpid(pid, NULL, 0) != pid) /* wait for first child */


printf("waitpid error");
exit(0);
}

To Run the Program

[root@localhost /]# cc avoidzombie.c


[root@localhost /]# ./a.out

OUTPUT

Second Child,parent pid=1

Prepared By: Darshan.K.R, Dept.of CS&E, SJBIT Page 15


Unix Systems Programming and Compiler Design Manual

9. Write a C/C++ program to implement the system function.


[root@localhost /]# gedit system.c

#include<sys/wait.h>
#include<errno.h>
#include<unistd.h>
#include<stdio.h>
#include<stdlib.h>

int system1(const char *cmdstring)


{
pid_t pid;
int status;

if (cmdstring == NULL)
return(1);

if ((pid = fork()) < 0)


{
status = -1;
}
else if (pid == 0)
{ /* child */
execl("/bin/sh", "sh", "-c", cmdstring, (char *)0);
_exit(127); /* execl error */
}
else /* parent */
while (waitpid(pid, &status, 0) < 0)
{
if (errno != EINTR)
status = -1; /* error other than EINTR from waitpid() */
break;
}

return(status);
}

int main()
{
int status;

if ((status = system1("date")) < 0)


printf("system() error");

if ((status = system1("who")) < 0)


printf("system() error");

exit(0);
}

Prepared By: Darshan.K.R, Dept.of CS&E, SJBIT Page 16


Unix Systems Programming and Compiler Design Manual

To Run The Program

[root@localhost /]# cc system.c


[root@localhost /]# ./a.out

OUTPUT
Sun Dec 30 08:38:10 IST 2012
root pts/0 2012-12-30 08:34 (:0.0)

Prepared By: Darshan.K.R, Dept.of CS&E, SJBIT Page 17


Unix Systems Programming and Compiler Design Manual

10. Write a C/C++ program to set up a real-time clock interval timer using the alarm API.
[root@localhost /]# gedit alarm.c

#include<signal.h>
#include<stdio.h>
#include<unistd.h>
#include<errno.h>

void wakeup()
{
printf("Hello\n");
printf("---------------------------------\n");
}

int main()
{
int i;
struct sigaction action;
action.sa_handler=wakeup;
action.sa_flags=SA_RESTART;
sigemptyset(&action.sa_mask);

if(sigaction(SIGALRM,&action,0)==-1)
{
perror("sigaction");
}
while(1)
{
alarm(5);
pause();
printf("Waiting For Alarm\n");
}
return 0;
}

To Run the Program

[root@localhost /]# cc alarm.c


[root@localhost /]# ./a.out

OUTPUT

Hello
---------------------------------
Waiting For Alarm
Hello
--------------------------------- (After 5 CPU Clockcycle)
Waiting For Alarm
Hello
--------------------------------- (After 5 CPU Clockcycle)
Waiting For Alarm

Prepared By: Darshan.K.R, Dept.of CS&E, SJBIT Page 18


Unix Systems Programming and Compiler Design Manual

11. Write a C program to implement the syntax-directed definition of “if E then S1” and
“if E then S1 else S2”.

[root@localhost /]# gedit sdd.c

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int parsecondition(char[],int ,char *,int);
void gen(char[],char[],char[],int);

int main()
{
int counter=0,stlen=0,elseflag=0;
char stmt[60];
char strB[54];
char strS1[50];
char strS2[45];

printf("format of if statement\n example............\n");


printf("if(a<b)then(s,a);\n");
printf("if(a<b)then(s,a) else (s,b);\n\n");
printf("enter the statement\n");
scanf("%s",&stmt);

stlen=strlen(stmt);
counter=counter+2;
counter=parsecondition(stmt,counter,strB,stlen);
if(stmt[counter]==')')
counter++;
counter=counter+3;
counter=parsecondition(stmt,counter,strS1,stlen);
if(stmt[counter+1]==';')
{
printf("\n parsing the input statement...\n");
gen(strB,strS1,strS2,elseflag);
return 0;
}
if(stmt[counter]==')')
counter++;
counter=counter+3;
counter=parsecondition(stmt,counter,strS2,stlen);
counter=counter+2;
if(counter==stlen)
{
elseflag=1;
printf("\n parsing the input statement");
gen(strB,strS1,strS2,elseflag);
return 0;
}
return 0;
}
Prepared By: Darshan.K.R, Dept.of CS&E, SJBIT Page 19
Unix Systems Programming and Compiler Design Manual

int parsecondition(char input[],int cntr , char *dest, int totallen)


{
int index=0,pos=0;
while(input[cntr]!='(' && cntr<=totallen)
cntr++;
if(cntr>=totallen)
return 0;
index=cntr;
while(input[cntr]!=')')
cntr++;
if(cntr>=totallen)
return 0;
while(index<=cntr)
dest[pos++]=input[index++];
dest[pos]='\0';
return cntr;
}
void gen(char B[],char S1[],char S2[],int elsepart)
{
int Bt=101,Bf=102,Sn=103;
printf("\n\t if %s goto %d",B,Bt);
printf("\n\t goto %d",Bf);
printf("\n %d:",Bt);
printf("%s",S1);
if(!elsepart)
printf("\n %d:",Bf);
else
{
printf("\n\t goto %d",Sn);
printf("\n %d : %s",Bf,S2);
printf("\n %d:",Sn);
}
}

To Run the Program

[root@localhost /]# cc sdd.c


[root@localhost /]# ./a.out

Prepared By: Darshan.K.R, Dept.of CS&E, SJBIT Page 20


Unix Systems Programming and Compiler Design Manual

OUTPUT

format of if statement
example............
if(a<b)then(s,a);
if(a<b)then(s,a) else (s,b);

enter the statement


if(a<b)then(s,a);

parsing the input statement...

if (a<b) goto 101


goto 102
101:(s,a)
102:

[root@localhost /]# ./a.out

format of if statement
example............
if(a<b)then(s,a);
if(a<b)then(s,a) else (s,b);

enter the statement


if(a<b)then(s,a)else(s,b);

parsing the input statement


if (a<b) goto 101
goto 102
101:(s,a)
goto 103
102 : (s,b)
103:

Prepared By: Darshan.K.R, Dept.of CS&E, SJBIT Page 21


Unix Systems Programming and Compiler Design Manual

12. Write a yacc program that accepts a regular expression as input and produce its parse
tree as output

[root@localhost /]# gedit parse.y

%{
#include<ctype.h>
char str[20];
int i=0;
%}
%token id
%left '+''/''*''-'
%%
E:S {infix_postfix(str);}
S:S'+'T|S'-'T
|T
T:T'*'F|T'/'F
|F
F:id|'('S')'
;
%%
#include<stdio.h>
main()
{
printf("\n Enter the grammar:");
yyparse();
}
yyerror()
{
printf("invalid");
}
yylex()
{
char ch=' ';
while(ch!='\n')
{
ch=getchar();
str[i++]=ch;
if(isalpha(ch)) return id;
if(ch=='+'||ch=='*'||ch=='-'||ch=='/') return ch;}
str[--i]='\0';
return(0);
exit(0);
}

void push(char stack[],int *top, char ch)


{
stack[++(*top)]=ch;
}

Prepared By: Darshan.K.R, Dept.of CS&E, SJBIT Page 22


Unix Systems Programming and Compiler Design Manual

char pop(char stack[],int *top)


{
return(stack[(*top)--]);
}
int prec(char ch)
{
switch(ch)
{
case '/' :
case '*' : return 2;
case '+' :
case '-' : return 1;
case '(' : return 0;
default : return -1;
}
}
void infix_postfix(char infix[])
{
int top=-1,iptr=-1,pptr=-1;
char postfix[20],stack[20],stksymb,cursymb;
push(stack,&top,'\0');
while((cursymb=infix[++iptr])!='\0')
{
switch(cursymb)
{
case '(' : push(stack,&top,cursymb);
break;
case ')' : stksymb=pop(stack,&top);
while(stksymb!='(')
{
postfix[++pptr]=stksymb;
stksymb=pop(stack,&top);
}
break;
case '*' :
case '/' :
case '+' :
case '-' : while (prec(stack[top])>=prec(cursymb))
postfix[++pptr]=pop(stack,&top);
push(stack,&top,cursymb);
break;
default : if(isalnum(cursymb)==0)
{
printf("error in input:");
exit(0);
}
postfix[++pptr]=cursymb;
} }
while(top!=-1)
postfix[++pptr]=pop(stack,&top);
printf("%s\n",postfix);
}

Prepared By: Darshan.K.R, Dept.of CS&E, SJBIT Page 23


Unix Systems Programming and Compiler Design Manual

To Run the Program

[root@localhost /]# yacc –d parse.y


[root@localhost /]# cc y.tab.c –ll
[root@localhost /]#./a.out

OUTPUT

Enter the grammar:(a*b)+c-(d*e)


ab*c+de*-

Prepared By: Darshan.K.R, Dept.of CS&E, SJBIT Page 24


Unix Systems Programming and Compiler Design Manual

VIVA Question

1. What are the differences between ANSI C and K & R C?


2. Explain feature test macros. Write a C/C++ POSIX compliant program that is
supported on any given system using feature test macros.
3. Explain the common characteristics of API and describe the error status codes.
4. Describe the characteristics of POSIX.1 FIPS standard and X/Open standard.
5. Differentiate between ANSI C and C++ standards
6. Explain the different file types available in UNIX and POSIX systems
7. Differentiate between hard links and symbolic links with an example.
8. Describe Inode table entries
9. Write a C/C++ program to emulate the UNIX mv command
10. Explain how fcntl API is used for file and record locking.
11. Write the code segment in C that reads utmost 100 bytes into a variable but from
standard input.
12. List and explain the access mode flags and access modifier flags. Also explain how
the permission value specified in an ‘open’ call is modified by its calling process
‘umask’ value.
13. Explain the process of changing user and group ID of files
14. What are named pipes? Explain with an example the use of lseek, link, access with
their prototypes and argument values.
15. Describe the structure of stat system call along with declarations. Also write struct
stat structure.
16. Write a C program to implement the UNIX chown functions
17. Explain Open, Creat, read and fcntl APIs with example
18. With an example program, explain the use of setjmp and longjmp functions.
19. Explain how a C program can be started and various ways of termination.
20. Briefly explain the memory layout of a C program
21. What is fork and vfork? Explain with an example program for each.
22. What is a zombie process?
23. How does UNIX operating system keep process accounting? Write a program to
generate accounting data and give its process structure.
24. Write a C/C++ program to obtain process attributes.
25. Explain wait, waitpid, wait3 and wait4 functions with their prototypes and uses

Prepared By: Darshan.K.R, Dept.of CS&E, SJBIT Page 25


Unix Systems Programming and Compiler Design Manual

26. Explain different exec functions? Describe how their functioning differs from each
other.
27. Write short notes on Race condition
28. Write a program that execs an interpreter file.
29. What is process Identifier? Mention the commands for getting different ID’s of calling
process

Prepared By: Darshan.K.R, Dept.of CS&E, SJBIT Page 26

You might also like