7 Replies - 586 Views - Last Post: 10 November 2017 - 07:00 AM Rate Topic: -----

#1 Graemo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 09-November 17

Zombie Processes Linux

Posted 09 November 2017 - 01:47 PM

Hello!

I am writing a program that creates 3 processes that print on the screen abc ab ac all the time. But when i close with ctrl+c i get zombie processes, How can i solv this isue?
Is This A Good Question/Topic? 0
  • +

Replies To: Zombie Processes Linux

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13492
  • View blog
  • Posts: 53,892
  • Joined: 12-June 08

Re: Zombie Processes Linux

Posted 09 November 2017 - 01:50 PM

Why would you have a process that prints to the screen all that junk?

What does the app do that it doesn't break right?
Was This Post Helpful? 0
  • +
  • -

#3 Graemo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 09-November 17

Re: Zombie Processes Linux

Posted 09 November 2017 - 02:12 PM

View Postmodi123_1, on 09 November 2017 - 01:50 PM, said:

Why would you have a process that prints to the screen all that junk?

What does the app do that it doesn't break right?


---------------
Real time operating system, to deeper understand how processes work and how harmful are zombie processes.
My question is how can i prevent this, mean prevent zombie processes run in background.
I have attached the files if you want chek the source code.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13492
  • View blog
  • Posts: 53,892
  • Joined: 12-June 08

Re: Zombie Processes Linux

Posted 09 November 2017 - 02:15 PM

Copy/paste the code here and please use the 'code' tag button in the editor.

Do you want the app to be programmed to prevent this or the OS?
Was This Post Helpful? 0
  • +
  • -

#5 Graemo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 09-November 17

Re: Zombie Processes Linux

Posted 09 November 2017 - 02:24 PM

View Postmodi123_1, on 09 November 2017 - 02:15 PM, said:

Copy/paste the code here and please use the 'code' tag button in the editor.

Do you want the app to be programmed to prevent this or the OS?

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



void WaitP(char * signalName)
{
	while(unlink(signalName) == -1);
	
}

void SignalV(char * signalName)
{

	open(signalName, O_CREAT, O_RDWR, 00777);
}

----------------

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

/* Feel free to change process name to your liking. */
#define PROGRAM_A "./process_a"
#define PROGRAM_B "./process_b"
#define PROGRAM_C "./process_c"

const int FALSE=0;
const int TRUE=1;

void cleanup(){}


int main(void)
{
	int processid;

		if ((processid=fork()) == 0)
	{
		execlp(PROGRAM_A,PROGRAM_A,NULL);

	
		printf("\n\"%s\" Could not be executed. Make sure that executable exists.\n",PROGRAM_A);
		exit(-1);
	}
	if ((processid=fork()) == 0)
	{
		execlp(PROGRAM_B,PROGRAM_B,NULL);


		printf("\n\"%s\" Could not be executed. Make sure that executable exists.\n",PROGRAM_B)/>/>;
		exit(-1);
	}
	if ((processid=fork()) == 0)
	{
		execlp(PROGRAM_C,PROGRAM_C,NULL);


		printf("\n\"%s\" Could not be executed. Make sure that executable exists.\n",PROGRAM_C);
		exit(-1);
	}

    printf("\nProcessess has started. Use \"top\" and/or \"ps\" to verify. ");

	
	return 0;
}

--------------------------------

#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include "header.h"

const int FALSE=0;
const int TRUE=1;



int main(void)
{	
	printf("(abc) A");
	fflush(stdout);
	SignalV("B");
	WaitP("A");
	sleep(2);
	

	
	while(1)
	{	
		printf(" \n(ab) A");
		fflush(stdout);
		SignalV("B");
		WaitP("A");
		sleep(2);
		
		printf(" \n(ac) A");
		fflush(stdout);
		SignalV("C");
		WaitP("A");
		sleep(2);
	}

	return 0;
}

-------------------------------

#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include "header.h"

const int FALSE=0;
const int TRUE=1;



int main(void)
{
	WaitP("B"); 
	printf("B");
	fflush(stdout);
	SignalV("C");
	WaitP("B");

	while(1)
	{	
		printf("B");
		fflush(stdout);
		SignalV("A");
		WaitP("B");
		
	}

	return 0;
}

---------------------------------

#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include "header.h"

const int FALSE=0;
const int TRUE=1;



int main(void)
{	
	WaitP("C"); 
	printf("C");
	fflush(stdout);
	SignalV("A");
	WaitP("C");

	while(1)
	{	
		printf("C");
		fflush(stdout);
		SignalV("A");
		WaitP("C");
		
	}

	return 0;
}
:code:

This post has been edited by modi123_1: 09 November 2017 - 02:38 PM
Reason for edit:: In the future, please use the [code] tag button in the editor.

Was This Post Helpful? 0
  • +
  • -

#6 Graemo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 09-November 17

Re: Zombie Processes Linux

Posted 10 November 2017 - 02:23 AM

Anyone who could see where is the problem?
Was This Post Helpful? 0
  • +
  • -

#7 no2pencil  Icon User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6552
  • View blog
  • Posts: 30,682
  • Joined: 10-May 07

Re: Zombie Processes Linux

Posted 10 November 2017 - 06:42 AM

Quote

#define PROGRAM_A "./process_a"
#define PROGRAM_B "./process_b"
#define PROGRAM_C "./process_c"


Does this mean you are just calling/executing 3 binary files from this main process, like a wrapper?
Was This Post Helpful? 0
  • +
  • -

#8 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 5895
  • View blog
  • Posts: 20,130
  • Joined: 05-May 12

Re: Zombie Processes Linux

Posted 10 November 2017 - 07:00 AM

View PostGraemo, on 09 November 2017 - 03:47 PM, said:

I am writing a program that creates 3 processes that print on the screen abc ab ac all the time. But when i close with ctrl+c i get zombie processes, How can i solv this isue?

Don't write code with infinite loops. :)

Seriously, though. What is the point of your 3 separate programs which seem to have an incestuous dependency on each other and seems to be ripe for deadlocks.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1