Obtaining foreground process group ID of other terminal using system calls

Sreeram B S sreeramabsc at yahoo.com
Fri Dec 16 04:15:27 UTC 2005


  Hi friends, 
  How can I obtain the foreground process group ID of other terminals using C system calls? 
  Suppose, that I am working on /dev/tty1. Now, if I want my program to obtain the foreground process group ID of terminal /dev/tty2, then which system call should I use? Also, kindly tell me the usage of that system call. 
  I tried ioctl() system call, but it failed. The program in which I used ioctl() (but failed) is: 
   
  -----------------------------------------------------------------------------
  #include <stdio.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>

int main() {
int pid;
int fd;

fd = open("/dev/tty1", O_RDONLY);
if ( fd == -1 )
{
perror ("open");
exit (1);
}

if ( ioctl(fd, TIOCGPGRP, &pid) == -1 )
{
perror ("ioctl");
exit (1);
}

printf ("PGRP = %d\n", pid);
exit (0);
} 
  
The error I am getting is this: 
  ioctl: Inappropriate ioctl for device
  ------------------------------------------------------------------------------
   
  Kindly suggest me as to how I can achieve the task? 
   
  Thanks, 
  Sreeram


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.busybox.net/pipermail/busybox/attachments/20051215/22c6d36e/attachment-0001.htm 


More information about the busybox mailing list