Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 08-11-2004, 01:48 AM   #1 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,705
redhead is on a distinguished road
A request from Ali regarding Back OS processes

I got a personal message from Ali, and I thought it would be better if it was placed here, besides the reply message is too long for the private message system to send it.
Quote:
ali wrote on 08-11-2004 10:49 AM:
Think a program: executing back OS like services. How can I make this program with C/c++. Can you give me sample.
A back OS service? are you thinking of a deamon running in the background and not appearing in any joblist?

What OS is this to be run under ? windows/linux/OSF2/HP-UX ?

I have a solution for the *nix world, but windows is a different matter, it tends to not follow the ANSI standard so some of the system dependant calls are implemented different according to which compiler is beeing used.

*nix ei:
Code:
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <signal.h>

/*
 * Just a simple deamon making function, as suggested in
 * Unix Network programming, second edition.
 * fork() and close() all file descriptors with
 * stderr/stdout/stdin/etc, and finaly chroot your 
 * self to be running on your own.
 */

void deamon_init(const char* pname, int facility)
{
  int i;
  unsigned long pid;
  if((pid=fork())!=0)
    exit(0);
  setsid();
  signal(SIGHUP, SIG_IGN);
  if((pid=fork())!=0)
    exit(0);
  chdir("/");
  umask(0);
  for(i=0; i < MAXFD; i++)
    close(i);
}

int main(int argv, char* argc[])
{
  deamon_init(argv[0],0);
  /* 
   * rest of program will have no access to stdin/stdout/stderr 
   * And will only appear when the OS is questioned for hidden
   * processes
   */
  sleep(50);
  return 0;
}
Altho in the future a question like this would be better, if it were placed in the c/c++ programming section, so otheres in a simular situation can benefit from the solution
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
sending an xml request sde PHP 3 09-25-2003 12:38 PM


All times are GMT -8. The time now is 03:56 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting