#include <stdio.h>
#include <stdlib.h>
main()
{
int x;
srand((unsigned)time(NULL));
while((x=fork())==-1);
if (x==0)
{
sleep(rand() % 2);
printf("a");
}
else
{
sleep(rand() % 3);
printf("b");
}
printf("c");
}
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
int main()
{
pid_t pid;
pid = fork();
if (pid < 0)
{
fprintf(stderr, "Fork Failed");
return 1;
}
else if (pid == 0)
{
execlp("/bin/ls","ls",NULL);
}
else {
wait(NULL);
printf("Child Complete");
}
return 0;
}
#include <stdio.h>
#include <sys/types.h>
#include <sys/msg.h>
#include <sys/ipc.h>
#define MSGKEY 75
struct msgform
{
long mtype;
char mtext[1030];
}msg;
int msgqid,i;
void CLIENT()
{
int i;
msgqid=msgget(MSGKEY,0777);
for (i=10;i>=1;i--)
{
msg.mtype=i;
printf("(client) sent \n");
msgsnd(msgqid,&msg,1024,0);
}
exit(0);
}
void SERVER()
{
msgqid=msgget(MSGKEY,0777|IPC_CREAT);
do{
msgrcv(msgqid,&msg,1030,0,0);
printf("(Server) recieved\n");
} while(msg.mtype!=1);
msgctl(msgqid,IPC_RMID,0);
exit(0);
}
void main()
{
while((i=fork())==-1);
if(!i) SERVER();
while((i=fork())==-1);
if(!i) CLIENT();
wait(0);
wait(0);
}