0% found this document useful (0 votes)
22 views13 pages

2.os Lab 2

tq
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)
22 views13 pages

2.os Lab 2

tq
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/ 13

PROCESS MANAGEMENT

BY: RAJEEV RANJAN KUMAR TRIPATHI


ASSEMBLY CODE IN C
main()
{
asm mov AX, 10
asm mov BX, 20
asm add AX,BX
printf("\n Sum=%d", _AX);
getch();
}

Created By: Rajeev Ranjan Kumar Tripathi


PREVILAGED RESOURCE
register int a=10;
void main()
{
printf("\n Value of a=%d", a);
getch();
}

Created By: Rajeev Ranjan Kumar Tripathi


GETTING PROCESS ID
#include<process.h>
void main()
{
printf("\n Process id of this program=%u", getpid());
getch();
}

Created By: Rajeev Ranjan Kumar Tripathi


ABORTING A PROCESS
#include <stdio.h>
#include <stdlib.h>
void finish()
{
abort();
}
int main(void)
{
printf("\n I am the first and the last message");
finish();
printf("\n I will not be executed anymore");
}

Created By: Rajeev Ranjan Kumar Tripathi


A CHILD PROCESS
void main()
{
printf("\n I am a child process");
}

Created By: Rajeev Ranjan Kumar Tripathi


Syntax of spawnl
int spawnl(int mode, char *path, char *argv[]);

Created By: Rajeev Ranjan Kumar Tripathi


PARENT PROCESS (VERSION-1)
#include<process.h>
#include<stdio.h>
void main()
{
int result;
clrscr();
printf("\n Parent process is calling child.exe");
result = spawnl(P_WAIT, "child.exe", NULL);
if (result == -1)
{
perror("Error from spawnl");
}
printf("\n Again back in Parent process");
getch();
}

Created By: Rajeev Ranjan Kumar Tripathi


PARENT PROCESS(VERSION-2)
#include<process.h>
#include<stdio.h>
void main()
{
int result;
clrscr();
printf("\n Parent process is calling child.exe");
result = spawnl(P_OVERLAY, "child.exe", NULL);
if (result == -1)
{
perror("Error from spawnl");
}
printf("\n Again back in Parent process");
getch();
}

Created By: Rajeev Ranjan Kumar Tripathi


PASSING ARGUMENT TO MAIN
METHOD
int main(int argc, char *argv[])
{
int a, b, c;
a=atoi(argv[1]);
b=atoi(argv[2]);
c=a+b;
printf("\nSum=%d",c);
}

Created By: Rajeev Ranjan Kumar Tripathi


PASSING ARGUMENTS TO CHILD
PROCESS
#include<process.h>
#include<stdio.h>
void main()
{
int result;
char *argv[]={"10","20"};
clrscr();
printf("\n Parent process is calling child.exe");
result = spawnl(P_OVERLAY, "child1.exe",argv);
if (result == -1)
{
perror("Error from spawnl");
}
printf("\n Again back in Parent process");
getch();
}

Created By: Rajeev Ranjan Kumar Tripathi


ASSIGNING FUNCTION PRIORITY
void before()
{
clrscr();
printf("\n I will be displayed before main");
}
#pragma startup before
void main()
{
printf("\n I am main");
}
void after()
{
printf("\n I will be displayed after main");
getch();
}
#pragma exit after

Created By: Rajeev Ranjan Kumar Tripathi


Session Ends

You might also like