Notification email in C program, via system call? or?


 
Thread Tools Search this Thread
Top Forums Programming Notification email in C program, via system call? or?
# 1  
Old 03-10-2011
Notification email in C program, via system call? or?

Hello everyone!
I'm quite new here, but this forum helped me a lot before without registering :-)
I'll go directly to my problem, I have been searching a bit about this issue but I was not successful.
I need to write a program in C code to notificate me (to my email) when some action is done (doesn't matter which, let's say when user login). I have tried to use using system call (system) this: echo "User has logged on." | mail -s "Notification" my@mail.com - this works nicely but it takes quite a lot of time (approx 1min) and I have to use system call inside C code - I think it's not an elegant way to do so. I need this to be almost realtime fast - I mean the action takes place and in let's say 3-5sec the mail is sent.
Is there any chance to solve this issue? It doesn't have to be with usage of system call, but I need to use it in C program. Any help is appreciated! Thanks, yours RoNNo

PS: English is not my mother tongue, so I apologize for it.
# 2  
Old 03-10-2011
Moving thread to the programming area.
# 3  
Old 03-10-2011
First, whatever is hanging the child processes you spawn off with your call to system() will probably cause the same problem no matter how you get around it.

Second, what the mail program does is pretty complex. Duplicating that would be a lot of work, and you won't do it as well as the mail program does.

Finding out why "echo ... | mail ..." is so slow is your best option.

If you're on Linux, run the mail utility under strace. If Solaris, use truss. Look at the man page for the one you need to use, then look in the output and find out where the mail program is taking so long.
# 4  
Old 03-10-2011
Thanks for help, I have no experience with using strace, this is what it returns:
Code:
execve("/bin/echo", ["echo", "somthing"], [/* 23 vars */]) = 0
brk(0)                                  = 0x8a7b000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7813000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY)      = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=70884, ...}) = 0
mmap2(NULL, 70884, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7801000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/tls/i686/cmov/libc.so.6", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0000m\1\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=1405508, ...}) = 0
mmap2(NULL, 1415592, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb76a7000
mprotect(0xb77fa000, 4096, PROT_NONE)   = 0
mmap2(0xb77fb000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x153) = 0xb77fb000
mmap2(0xb77fe000, 10664, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb77fe000
close(3)                                = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb76a6000
set_thread_area({entry_number:-1 -> 6, base_addr:0xb76a68d0, limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1}) = 0
mprotect(0xb77fb000, 8192, PROT_READ)   = 0
mprotect(0x804f000, 4096, PROT_READ)    = 0
mprotect(0xb7831000, 4096, PROT_READ)   = 0
munmap(0xb7801000, 70884)               = 0
brk(0)                                  = 0x8a7b000
brk(0x8a9c000)                          = 0x8a9c000
open("/usr/lib/locale/locale-archive", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/locale.alias", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=2570, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7812000
read(3, "# Locale name alias data base.\n#"..., 4096) = 2570
read(3, "", 4096)                       = 0
close(3)                                = 0
munmap(0xb7812000, 4096)                = 0
open("/usr/lib/locale/en_US.utf8/LC_IDENTIFICATION", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=373, ...}) = 0
mmap2(NULL, 373, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7812000
close(3)                                = 0
open("/usr/lib/gconv/gconv-modules.cache", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=26048, ...}) = 0
mmap2(NULL, 26048, PROT_READ, MAP_SHARED, 3, 0) = 0xb780b000
close(3)                                = 0
open("/usr/lib/locale/en_US.utf8/LC_MEASUREMENT", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=23, ...}) = 0
mmap2(NULL, 23, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb780a000
close(3)                                = 0
open("/usr/lib/locale/en_US.utf8/LC_TELEPHONE", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=59, ...}) = 0
mmap2(NULL, 59, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7809000
close(3)                                = 0
open("/usr/lib/locale/en_US.utf8/LC_ADDRESS", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=155, ...}) = 0
mmap2(NULL, 155, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7808000
close(3)                                = 0
open("/usr/lib/locale/en_US.utf8/LC_NAME", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=77, ...}) = 0
mmap2(NULL, 77, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7807000
close(3)                                = 0
open("/usr/lib/locale/en_US.utf8/LC_PAPER", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=34, ...}) = 0
mmap2(NULL, 34, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7806000
close(3)                                = 0
open("/usr/lib/locale/en_US.utf8/LC_MESSAGES", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
close(3)                                = 0
open("/usr/lib/locale/en_US.utf8/LC_MESSAGES/SYS_LC_MESSAGES", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=57, ...}) = 0
mmap2(NULL, 57, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7805000
close(3)                                = 0
open("/usr/lib/locale/en_US.utf8/LC_MONETARY", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=286, ...}) = 0
mmap2(NULL, 286, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7804000
close(3)                                = 0
open("/usr/lib/locale/en_US.utf8/LC_COLLATE", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=1170770, ...}) = 0
mmap2(NULL, 1170770, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7588000
close(3)                                = 0
open("/usr/lib/locale/en_US.utf8/LC_TIME", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=2454, ...}) = 0
mmap2(NULL, 2454, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7803000
close(3)                                = 0
open("/usr/lib/locale/en_US.utf8/LC_NUMERIC", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=54, ...}) = 0
mmap2(NULL, 54, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7802000
close(3)                                = 0
open("/usr/lib/locale/en_US.utf8/LC_CTYPE", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=256324, ...}) = 0
mmap2(NULL, 256324, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7549000
close(3)                                = 0
fstat64(1, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7548000
write(1, "somthing\n", 9)               = 9
close(1)                                = 0
munmap(0xb7548000, 4096)                = 0
close(2)                                = 0
exit_group(0)                           = ?

Everything is done in sec, and it stops at exit_group(0) =
where is empty field, then here comes ? after about 1min and console is ready for use again.

Last edited by pludi; 03-10-2011 at 12:52 PM..
# 5  
Old 03-10-2011
It's waiting for a process to quit... Its return value is unknown because exit_group in fact has no return value.

I think you need to run strace -f to follow a process and its children.
# 6  
Old 03-10-2011
When I run it with strace -f, it just returns the same. I'm kinda desperate, now normal echo message |mail -s "some subject" my@mail.com stopped to work even with delay, am I doing something wrong?
# 7  
Old 03-11-2011
I can't tell without seeing your code.

I think you chopped off the interesting bits of your strace output, the "echo" may happen well after the mail process is created.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Email Notification

Hi All, I need write a linux script which emails each record to the employee manager email-id which will be specified inside the file. Each employee can have a different manager too.. file contain 200 to 300 records Employee ID, Employee Name, Employee Email-ID, Manager, Manager... (4 Replies)
Discussion started by: tradingspecial
4 Replies

2. Homework & Coursework Questions

Help with Execl system call in a C program?

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: "Your a7.c program should use printf to print a nice message. (You can decide what to say.) Then the process... (9 Replies)
Discussion started by: miniviking10
9 Replies

3. Shell Programming and Scripting

Add Email Notification to Rsync

HI what i need to be able to do is add a email to the end of a rsync. my current ion configures writes a daily log to disk, but real want to send the log to a central email address. The current script is as below, is this possible? #!/bin/bash if then rsync -aWv --stats progress... (3 Replies)
Discussion started by: treds
3 Replies

4. Homework & Coursework Questions

program to send messages to parent using pipes and select system call

Write a program using select, which will create some number of child processes that continuously send text messages to the parent process using pipes. Each child has its own pipe that it uses to communicate with the parent. The parent uses select () to decide what pipes should be processed to... (1 Reply)
Discussion started by: ripssingh
1 Replies

5. UNIX for Advanced & Expert Users

Linux-Heartbeat Email Notification

hi guys I hope this goes here Have someone used Linux heartbeat to send email when the Slave server becomes the Master? I've read I can configure the MailTo under /etc/ha.d/resource.d but I really don't know how to do it. I basically need my primary server to send an email when it... (2 Replies)
Discussion started by: karlochacon
2 Replies

6. Programming

A question about the system call mount in a C program

Dear all, Currently I'm working on a C program (OS = ubuntu 9.0.4)in which a USB key will be mounted and umounted for several times. I read the man page of the mount system call. I use the following test code #include <sys/mount.h> int main(int argc, char *argv) { if... (5 Replies)
Discussion started by: dariyoosh
5 Replies

7. AIX

Cron Job notification email

Hi, I'm fairly new to Aix and am looking for some help on the following. I have setup a cron job under root and want it to send the email once it's run to an external email address. I can get it to send the output in an email to me by using mail on the end of the crontab entry. But I would... (1 Reply)
Discussion started by: elmesy
1 Replies

8. AIX

Problem with Cron Email Notification

I have two different cron jobs that run on the same days. The jobs are 7 hours apart. Both jobs are set to send notification emails when they start running. Both jobs always run successfully, but I only receive an email from the first job. I never get the email from the second job. ... (1 Reply)
Discussion started by: sasaliasim
1 Replies

9. UNIX for Dummies Questions & Answers

How to add email notification in scripts?

Hi. I want to add email notification so when the my script finishes it sends out an email of the results to our team. If there are errors the subject on the email should say there were errors. If any having idea/sample scripts pls share with me. (2 Replies)
Discussion started by: redlotus72
2 Replies

10. Post Here to Contact Site Administrators and Moderators

Why am I not recieving email notification?

I have been a member for almost a year now. I have always recieved email notifications when I select "subcribe to this thread" at the bottom of posts that I reply to. However, over the last month or so, I have not been recieving email notification of replys to posts I respond to. I have... (6 Replies)
Discussion started by: Kelam_Magnus
6 Replies
Login or Register to Ask a Question