- Community Home
- >
- Servers and Operating Systems
- >
- Legacy
- >
- Operating System - Tru64 Unix
- >
- Re: kill does not return error when pid does not e...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2006 08:45 PM
тАО07-12-2006 08:45 PM
kill does not return error when pid does not exist
Unfortunately, kill always return 0, even when the pid killed is dead.
Here is the code sample that demonstrate that :
#include
#include
#include
int pid_fils ;
int Son( void ) ;
int Father( void ) ;
const char * getDateTime( void )
{
struct timeval tp ;
struct tm * time_tm ;
char microsec[20] ;
static char time_msg[100] ;
/* get the current date and time */
gettimeofday( & tp, NULL ) ;
time_tm = localtime( & tp.tv_sec ) ;
strftime( time_msg, 25, "%H:%M:%S", time_tm ) ;
sprintf( microsec, "%06ld", tp.tv_usec ) ;
strcat( time_msg, ":" ) ;
strcat( time_msg, microsec ) ;
return time_msg ;
}
int main( int argc, char * argv[] )
{
printf("Begin : %s\n", getDateTime() ) ;
pid_fils = fork() ;
if( pid_fils == 0 )
{
printf("Son : pid = %d\n", getpid() ) ;
Son() ;
}
else
{
printf("Pere : pid of the son = %d\n", pid_fils ) ;
Father() ;
}
return 0 ;
}
int Son( void )
{
sleep( 5 ) ;
printf("Son : end at %s\n", getDateTime() ) ;
return 23 ;
}
int Father( void )
{
while ( kill( pid_fils, 0 ) != -1 )
{
printf("Father : wait for end of %d at %s\n", pid_fils, getDateTime() ) ;
sleep( 1 ) ;
}
printf("Father : %d terminated\n" ) ;
printf("Father : end at %s\n", getDateTime() ) ;
return 46 ;
}
The output of this program is :
Begin : 10:39:16:466291
Pere : pid of the son = 8277
Son : pid = 8277
Father : wait for end of 8277 at 10:39:16:469851
Father : wait for end of 8277 at 10:39:17:476504
Father : wait for end of 8277 at 10:39:18:486445
Father : wait for end of 8277 at 10:39:19:496379
Father : wait for end of 8277 at 10:39:20:506327
Son : end at 10:39:21:476340
Father : wait for end of 8277 at 10:39:21:516323
Father : wait for end of 8277 at 10:39:22:526253
Father : wait for end of 8277 at 10:39:23:536220
Father : wait for end of 8277 at 10:39:24:546165
which means that the father process, using kill, does not detect the end of the son process.
Can anyone help me and explain why this program does not work ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2006 02:25 AM
тАО07-17-2006 02:25 AM
Re: kill does not return error when pid does not exist
*) the first argument to kill(2) should be of type pid_t, not int.
*) what does kill(1) return for the child process? I.e. from the shell, what is the output from
$ kill -0 child_pid
(both before and after the child process finish)
*) is the child process visible from ps(1) after it has returned from main()?
Also what version of Tru64 do you use, and how do you compile the program?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2006 02:34 AM
тАО07-17-2006 02:34 AM
Re: kill does not return error when pid does not exist
The system is HP-UX 11.00 as shown with the result of uname -a :
HP-UX tax124 B.11.00 U 9000/800 1127991527 unlimited-user license
I compile with the ordinary cc compiler. what cc returns the result :
/usr/bin/cc:
LINT B.11.11.06 CXREF B.11.11.06
HP92453-01 B.11.11.06 HP C Compiler
$ Sep 8 2000 23:13:51 $
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2006 02:36 AM
тАО07-17-2006 02:36 AM
Re: kill does not return error when pid does not exist
After the child is finished, it returns 0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2006 02:38 AM
тАО07-17-2006 02:38 AM
Re: kill does not return error when pid does not exist
PID TTY TIME COMMAND
16459 pts/1 0:00 a.out
16460 pts/1 0:00
So the child is visible with the command =
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2006 02:48 AM
тАО07-17-2006 02:48 AM
Re: kill does not return error when pid does not exist
I can find in "man exit" the following explication :
If the parent process of the calling process is not executing a wait(), wait3(), or waitpid(), and does not have SIGCLD set to SIG_IGN, the calling process is transformed into a zombie process.
So I have just to put in the father process the line :
signal ( SIGCLD, SIG_IGN ) ;
and now my process is working and the father process detects the end of the child process.
Thank you for your help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2006 04:20 PM
тАО07-17-2006 04:20 PM
Re: kill does not return error when pid does not exist
This one is a Tru64 forum and the program works as expected on my Tru64 box!