Sponsored Content
Full Discussion: Create a group of process
Top Forums Programming Create a group of process Post 302963571 by mattdj on Sunday 3rd of January 2016 06:43:34 AM
Old 01-03-2016
Create a group of process

Hi all ! Smilie

What I want?
1. All child process must be in the same group of process. Parent is a leader of the group.

How to do this? I would be greatfull of some example of code, I read about setsid but I can't even start...

My code so far:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>



int main(int argc, char *argv[])
{
  int i ; 
  pid_t pid; 

  int val;
  char *endptr;  
  
   if(argc != 2)
   {
        fprintf(stderr,"Error  \n");
        exit(EXIT_FAILURE);
   }

   val = strtol(argv[1],&endptr, 0);
   if(endptr == argv[1])
   {
        fprintf(stderr,"Bad number ! \n");
        exit(EXIT_FAILURE);
   }

   // okej

   if(setsid() == -1)
   {
	perror("setsid");
   }

   for(i = 0; i < val; i++)
   {
	pid = fork(); 
	if(pid < 0)
	{
		perror("Fork");		
        }
        else if(pid==0)
	{
	    int ret; 
		
	    /* Child process */
	    printf("child process");	
 	    ret = execl("program1","program1", "145",NULL); //  I run my second program 
	    if(ret == -1)	
	    	perror("Execl");
	
	}
	else{
		wait(NULL); 
	}
   } 
}

 

10 More Discussions You Might Find Interesting

1. AIX

Unable to create a group

Hi, I'm trying to create a new group on an AIX 5.2.0.0. server but am getting the following error: root:/root $ mkgroup debt 3004-698 Error committing changes to "debt" : Value is invalid. I've change the group name to no affect. Does anyone have any ideas what could be causing this? ... (0 Replies)
Discussion started by: m223464
0 Replies

2. UNIX for Advanced & Expert Users

How to create a dummy process of a process already running?

Hi Everybody, I want to create a shell script named as say "jip" and it is runned. And i want that when i do ps + grep for the process than this jip should be shown as process. Infact there might be process with name jip which is already running. (3 Replies)
Discussion started by: shambhu
3 Replies

3. Shell Programming and Scripting

create group in unix

Hi, I want to create group in unix. what is the command? how to create a group and add a user into that group? Thanks in advance (2 Replies)
Discussion started by: senthil_is
2 Replies

4. Homework & Coursework Questions

Create group in phonebook...

Use and complete the template provided. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Hi, I am creating the phonebook shell script to store the name, number and address of the people. I am stuck in one point.I have done to add new user,... (2 Replies)
Discussion started by: coolgal
2 Replies

5. AIX

How to create new user and add group

Hello, I am new in AIX please tell how can i create user and add group in this user for example, i want to create user umair and want to add this user primanry group DBA and secondary group ORACLE,how can i do this please tell in detail Thanks, Umair (1 Reply)
Discussion started by: umair
1 Replies

6. UNIX for Dummies Questions & Answers

create new group/delete existing group

Hi, please let me know the commands to create new group/delete existing group in unix and assigning users to newly created group. Thank you in advance. (2 Replies)
Discussion started by: kancherla.sree
2 Replies

7. AIX

Create new Volume Group

Good afternoon all, I'll probably confuse everyone as I'm a Windows guy dealing with AIX 6.1 and can't quite figure out how to do something. I have a P520 server running 2 LPARs and we have an IVM (not HMC).Within the IVM under Virtual Storage Management, when I check the Physical Volumes, I have... (4 Replies)
Discussion started by: Spellbound
4 Replies

8. Solaris

Create file for group of data:

Hi folks, I have the following data.Any help is greatly appreciated. order File_name 7222245 7222245.pdf 7222245 7222245a.pdf 7222245 7222245b.pdf 7222245 7222245c.pdf 7222245 7222245d.pdf 7222250 ... (1 Reply)
Discussion started by: kumar444
1 Replies

9. UNIX for Dummies Questions & Answers

How to create a volume group, logical volume group and file system?

hi, I want to create a volume group of 200 GB and then create different file systems on that. please help me out. Its becomes confusing when the PP calculating PP. I don't understand this concept. (2 Replies)
Discussion started by: kamaldev
2 Replies

10. UNIX for Dummies Questions & Answers

How to create a Group with rwx permission?

I want to create a GROUP with rwx permission. Also, I want to create a GROUP with root privileges, so that next time i create a user, I just need to add it to any of the groups and privileges automatically applied. please help. Thanks, Shouvanik (4 Replies)
Discussion started by: shouvanik
4 Replies
setpgid(3)						     Library Functions Manual							setpgid(3)

Name
       setpgid - set process group (POSIX)

Syntax
       #include <sys/types.h>
       int
       setpgid(pid, pgrp)
       pid_t pid, pgrp;

Description
       The  function is used to either join an existing process group or create a new process group within the session of the calling process (see
       Upon successful completion, the process group ID of the process that has a process ID which matches pid is set to pgrp.	If  pid  is  zero,
       then the call applies to the current process. In addition, if pgrp is zero, the process ID of the indicated process is used.

       This function is available only in the POSIX environment.

Return Values
       The  function  returns 0 when the operation is successful.  If the request fails, -1 is returned and the global variable indicates the rea-
       son.

Diagnostics
       The function fails and the process group is not altered if one of the following occurs:

       [EACCES]       The value of the pid argument matches the process ID of a child process of the calling process and  the  child  process  has
		      successfully executed an function.

       [EINVAL]       The value of the pgrp argument is less than zero or is not a supported value.

       [EPERM]	      The process indicated by the pid argument is a session leader.

		      The  value of the pid argument matches the process ID of a child process of the calling process and the child process is not
		      in the same session as the calling process.

		      The value of the pgrp argument does not match the process ID of the process indicated by the pid argument and  there  is	no
		      process with a process group ID that matches the value of the pgrp argument in the same session as the calling process.

       [ESRCH]	      The  value  of  the  pid	argument  does	not  match the process ID of the calling process of a child process of the calling
		      process.

See Also
       getpgrp(2), setsid(2)

																	setpgid(3)
All times are GMT -4. The time now is 12:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy